是否有多个进程在同一端口上侦听? [英] Multiple processes listening on same port or not?

查看:333
本文介绍了是否有多个进程在同一端口上侦听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Windows系统上.我已经在8080上启动了tomcat.我启动了也在8080上监听的nodejs程序.所以现在我有2个PID.当我执行netstat时,我在同一端口上找到两个PID.因此,一切都清楚地显示出来了.而且这两个过程都没有出现任何错误地运行.使我感到困惑的是,当我在浏览器上访问url localhost:8080时,它有时会显示tomcat主页,而其余时间则显示出nodejs响应.似乎进程之间存在竞争,就像谁先抓住它就会引发共鸣.接下来,当我看到重用同一端口时没有抛出任何错误时,我尝试打开另一个侦听8080的nodejs程序.但是这一次它抛出了一个错误,提示EADDRINUSE.这很令人困惑.如果必须抛出这样的错误,为什么首先要让nodejs和tomcat都监听8080?任何事实性的输入而没有任何猜想都将是有帮助的.

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.

推荐答案

您要么:

  • 在您的服务器前有一个代理
  • 您在不同的网络接口上运行服务器
  • 某种端口共享已在该计算机上设置.
  • 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.

这篇关于是否有多个进程在同一端口上侦听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆