Can a TCP port be re-used before TIME-WAIT expires?

时光怂恿深爱的人放手 提交于 2019-12-13 04:39:02

问题


We have a C# FTP class which works great but we are running out of TCP ports because they are all in the TIME-WAIT state and cannot be reused. We can decrease the default TIME-WAIT in the registry but we would rather reuse the ports.

So given the blog below: http://blogs.technet.com/b/networking/archive/2010/08/11/how-tcp-time-wait-assassination-works.aspx

In a situation where the server side socket goes to a TIME-WAIT state and the client reconnects to the server within 2MSL (default TIME-WAIT time), there are 2 things that can happen:

1.The server will not respond to the SYN packets from the client because the socket is in the TIME-WAIT state.

2.The server may accept the SYN from the client and change the state of the socket from TIME-WAIT to ESTABLISHED. This is known as TIME-WAIT assassination, or incarnation of a previous connection.

The key to scenario ‘2’ above is that the ISN (Initial Sequence number) of the SYN sent needs to be higher than the highest sequence number used in the previous session. If the ISN is not as expected, the server will not respond to the SYN and the socket will wait for 2MSL before being available for use again.

I am trying (programmatically in C#) to find a way to always send a SYN sent with a higher number than the highest sequence number used in previous session.

Is that possible to achieve?


回答1:


Windows already natively implements higher sequence numbers for you, you do not have to do anything special to get that functionality. The article you linked to states as much:

Microsoft’s TCP/IP implementation employs this functionality. ... TCP TIME-WAIT Assassination works very well between Windows systems and may not work as expected when Windows is communicating with hosts running other TCP/IP implementations. RFC1337, Hazards of TIME-WAIT Assassination, discusses possible pitfalls: http://tools.ietf.org/rfc/rfc1337.txt




回答2:


The ISN is random, by design. You can't control it from the API.



来源:https://stackoverflow.com/questions/22690992/can-a-tcp-port-be-re-used-before-time-wait-expires

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!