Listening 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 listening IP address, say 11.11.11.11 instead of 10.10.10.10 . Is there a way to "unlisten"?

+8
express
source share
3 answers

you need 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') }) }) 

must work

+23
source share

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

+1
source share

What you are trying to do is, in my opinion, rather unconventional. I would suggest server.close () . Close will wait for the whole request to complete and raise a close event. You can bind this event to listen on the new IP address. This is pretty weird.

0
source share

All Articles