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

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

问题描述

计算机是RHEL 5.3(内核2.6.18).

Machine is RHEL 5.3 (kernel 2.6.18).

有时候,我在netstat中注意到我的应用程序已建立连接,并且当 Local Address Foreign 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天全站免登陆