简体   繁体   中英

Disconnect http.createServer method in Node.js

I have a piece of code that uses the server with nodejs, in which there is a method that requires ports running programs then manually disconnected and reconnected to the same port.

but my trouble and not getting what method I use. sample code snippet:

var server = http.createServer(function(r, p){

   // Some Code

});
server.listen( 9999 );
server.on('error', function(e){ /*  */ });

I want to use the same port 9999.

If you want to make the server stop listening on port 9999 you need to call the server.close method.

http://nodejs.org/api/http.html#http_server_close_callback

http://www.nodebeginner.org/#hello-world

var http = require("http");

http.createServer(function(request, response) {

  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();

}).listen(9999);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM