Multiple processes listening on same port or not?

2019-09-16 05:38发布

This is on Windows system. I have tomcat started on 8080. I have a nodejs program started which is also listening on 8080. So now I have 2 PIDs. When I do a netstat, I find two PIDs on the same port. So everything is clearly being shown. And these two processes ran without showing up any error. What baffled me is when I access the url localhost:8080 on the browser, it sometimes shows up tomcat home page and the rest of the time it shows up the nodejs response. Looks like there is a race between the processes as in whoever catches it first throws up a resonse. Next as I see that there is no error being thrown on reusing the same port, I try to open up another nodejs program listening on 8080. But this time it throws an error saying EADDRINUSE. This is confusing. If it had to throw such an error, why would it in the first place allow nodejs and tomcat both to listen on 8080? Any factual inputs and no conjectures would be helpful.

1条回答
放我归山
2楼-- · 2019-09-16 06:42

You either:

  • have a proxy in front of your servers
  • you run the servers on different network interfaces
  • some sort of port sharing has been setup on that machine.
查看更多
登录 后发表回答