Listen to a different IP address

前端 未结 4 1048
自闭症患者
自闭症患者 2020-12-10 02:34

This is my code:

var server = express();

// Create the HTTP server
http
    .createServer(server)
    .listen(80, \'10.10.10.10\');

Once t

相关标签:
4条回答
  • 2020-12-10 02:47

    I think the "unlisten" function you're looking for is called "close": http://nodejs.org/api/http.html#http_server_close_callback

    0 讨论(0)
  • 2020-12-10 02:51

    What your are trying to accomplish is quite non-standard in my opinion. I would suggest server.close(). Close will wait all request to finish and trigger the "close" event. You can bind on that event to listen on the new IP. This is quite weird tho.

    0 讨论(0)
  • 2020-12-10 03:01
    app.listen(3000,'0.0.0.0',function(){
      console.log('Server running at http://127.0.1.1:8000/')
    })
    

    will work with express

    0 讨论(0)
  • 2020-12-10 03:03

    you have to use server.close() not app.close()..

    var express = require('express')
      , http = require('http')
      , app = express()
      , server = http.createServer(app)
    
    app.get('/',function(req,res){
      ...
    })
    
    server.listen(8000,'127.0.0.1',function(){
     server.close(function(){
       server.listen(8001,'192.168.0.202')
     })
    })
    

    should work

    0 讨论(0)
提交回复
热议问题