[英]Listen to a different IP address
This is my code:这是我的代码:
var server = express();
// Create the HTTP server
http
.createServer(server)
.listen(80, '10.10.10.10');
Once the server has been started, how can I dynamically change the listened IP address, say to 11.11.11.11
instead of 10.10.10.10
.服务器启动后,如何动态更改监听的 IP 地址,比如
11.11.11.11
而不是10.10.10.10
。 Is there an "unlisten" method?有“不听”的方法吗?
you have to use server.close() not app.close()..你必须使用 server.close() 而不是 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应该管用
我认为您正在寻找的“不听”功能称为“关闭”: http : //nodejs.org/api/http.html#http_server_close_callback
What your are trying to accomplish is quite non-standard in my opinion.在我看来,你想要完成的事情是非常不标准的。 I would suggest server.close() .
我建议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.
您可以绑定该事件以侦听新 IP。 This is quite weird tho.
这很奇怪。
app.listen(3000,'0.0.0.0',function(){
console.log('Server running at http://127.0.1.1:8000/')
})
will work with express将与快递一起工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.