简体   繁体   中英

Multiple http servers running on different ports in node.js

http.createServer(onRequest).listen(8888);
http.createServer(onRequest).listen(8080);

In this case, I understand that two different http servers are created which listen to at different ports.

http.createServer(onRequestA).listen(8888);
http.createServer(onRequestB).listen(8080);

In this case the servers listen on various ports and also do different actions.

I have aa few questions.

  1. Are these two approaches commonly used in the real world?
  2. Is there really an advantage of snippet 1?
  3. If such multiple servers can be created, what is the maximum number of servers that can be created from a single node instance?

In answering your questions directly,

  1. Are these two approaches commonly used in the real world?
  • It depends on what you're trying to archive on those ports.
  1. Is there really an advantage of snippet 1?
  • It also depends on the action you plan to take on the ports, if you wanna run the same requests, it doesn't make sense running multiple ports.
  1. If such multiple servers can be created, what is the maximum number of servers that can be created from a single node instance?
  • You might want to NOTE : Standard practices say no non-root process gets to talk to the Internet on a port less than 1024 , and also remember that the maximum number you can go for the ports is 65536 ie (0 ~ 65535).

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