传出 TCP 端口与侦听端口匹配
的结果
lsof | grep 40006
我遇到了一个奇怪的事件,我生成
java 29722 appsrv 54u IPv6 71135755 0t0 TCP localhost:40006->localhost:40006 (ESTABLISHED)
通常我看到
java 30916 appsrv 57u IPv6 71143812 0t0 TCP localhost:43017->localhost:40006 (ESTABLISHED)
箭头两侧的端口不匹配。当 lsof 生成前一个结果时,即使套接字配置为 SO_REUSEADDR,我也无法启动尝试侦听端口 40006 的应用程序。
这会发生吗?应该吗?
uname 给出: Linux femputer 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
I've encountered a weird happenstance where the results of my
lsof | grep 40006
produced
java 29722 appsrv 54u IPv6 71135755 0t0 TCP localhost:40006->localhost:40006 (ESTABLISHED)
Generally I see
java 30916 appsrv 57u IPv6 71143812 0t0 TCP localhost:43017->localhost:40006 (ESTABLISHED)
where the ports do not match on either side of the arrow. While lsof was producing the former result, I could not start an application which attempts to listen on the port 40006 even though the socket is configured as SO_REUSEADDR.
Can this happen? Should it?
uname gives: Linux femputer 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以通过创建套接字,将其绑定到
127.0.0.1:40006
,然后使用connect()
将其绑定到127.0.0.1:40006 来安排此类连接
。 (注意:没有listen()
)。我相信这就是所谓的“主动-主动开放”。以下程序演示了这一点:
端口无法重用的原因是因为该端口没有侦听 - 它是传出端口。
It is possible to arrange such a connection by creating a socket, binding it to
127.0.0.1:40006
, thenconnect()
it to127.0.0.1:40006
. (Note: nolisten()
). I believe this is called an "active-active open".The following program demonstrates this:
The reason that the port cannot be re-used is because the port is not listening - it is an outgoing port.
难道两个
40006
端口位于不同的接口上?Could it be that the two
40006
ports were on different interfaces?