如何让 TCP 连接回到同一个端口? [英] How can you have a TCP connection back to the same port?

查看:27
本文介绍了如何让 TCP 连接回到同一个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

机器是 RHEL 5.3(内核 2.6.18).

Machine is RHEL 5.3 (kernel 2.6.18).

有时我在 netstat 中注意到我的应用程序有连接,当 Local AddressForeign Address 相同时建立了 TCP 连接.

Some times I notice in netstat that my application has connection, established TCP connection when Local Address and Foreign Address are same.

这里 其他人也报告了同样的问题.

Here same problem reported by someone else too.

症状与链接中描述的相同 - 客户端连接到本地运行的服务器的端口 X 端口.一段时间后,netstat 显示客户端已从 127.0.0.1:X 连接到 127.0.0.1:X

The symptoms are same as described in link - client connects to port X port of server running locally. After some time netstat shows that client has connection from 127.0.0.1:X to 127.0.0.1:X

怎么可能?

编辑 01

同时打开导致了问题(非常感谢 Hasturkun).您可以在 经典 TCP 状态图上看到它从 SYN_SENT 状态转换为 SYNC_RECEIVED

Simultaneous open is causing the problem (thanks a lot to Hasturkun). You can see it on classical TCP state diagram in transition from SYN_SENT state to SYNC_RECEIVED

推荐答案

这可能是 TCP 同时连接引起的(提到 有关 LKML 的帖子,另请参阅此处.

This may be caused by TCP simultaneous connect (mentioned on this post to LKML, see also here).

循环尝试连接到动态本地端口范围内的端口(可以在 /proc/sys/net/ipv4/ip_local_port_range 中看到)时,有可能成功服务器没有监听那个端口.

It's possible for a program looping on trying to connect to a port within the dynamic local port range (which can be seen in /proc/sys/net/ipv4/ip_local_port_range),to succeed while the server is not listening on that port.

在足够多的尝试中,用于连接的套接字可能绑定到正在连接的同一端口,由于前面提到的同时连接而成功.你现在神奇地有一个客户端连接到它自己

On a large enough number of attempts, the socket being used to connect may be bound to the same port being connected to, which succeeds due to previously mentioned simultaneous connect. You now magically have a client connected to itself

这篇关于如何让 TCP 连接回到同一个端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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