2MSL Analysis of TCP three-times handshake and shutdown

Source: Internet
Author: User

TCP/IP three handshake four times waving, is very important, this link and the closure process is also very simple, but why is three times handshake. And why wait for the 2MSL state. Most people may have heard the question, this blog on the synthesis of "TCP/IP Detailed: Volume One" to analyze the reasons:

Here is a look at the TCP three handshake four times the schematic diagram:


1. Why do you have to shake hands three times?

In order to avoid the failure of the connection message segment to reach the server. Consider such a normal situation:

Suppose the TCP connection is two times handshake. When the client sent a request to connect the message, because the network reason this message is lost, then the client for a period of time did not receive the confirmation of the server will send the request to connect the message again, the server received, both sides established a connection, and then data transmission, and finally closed the connection.

But consider that if the lost packet is not lost, just a network node for a long time stranded, then both sides have closed the connection, at this time the server received lost packets, that the client will establish a connection, because it is two times handshake so the server sent a confirmation message to the client, and changed to Establishes a connection state.

It is conceivable that the client does not initiate a connection so it ignores the server's confirmation, thus wasting the server's resources.

2. Why wait 2MSL time.

1. When the client's last confirmation of the connection of the message loss (fourth wave sent), the server will send a fin message again, waiting for the client to confirm, the client in the 2MSL received server retransmission message again confirmed (to prevent the client has been shut down at this time).

2 2MSL of time can make all the expired messages disappear (to prevent the impact of the new connection), if you do not wait for 2MSL, immediately establish a new connection, then close the connection before the failure of the message sent to the segment is likely to affect the connection.

However, TCP states that the socket pair (client ip/port and server IP and port) in the 2MSL state cannot be used again. If you create a new connection in 2MSL, you can use this socket pair, and when the failed packet arrives at the new connection again, the socket will accept the message, but in fact it is not the data for the new connection interaction, so this invalid packet cannot be used.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.