Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top