TCP three times handshake, four times goodbye

Source: Internet
Author: User
Tags ack

A picture explains clearly:

Note that when you close the link, the Client\server is likely to be a server, as long as it is possible to establish a TCP link;

Note:
1: The fin was sent only to indicate that the end could not continue sending the data (the application layer could not call send sent), but it could also receive data;

2: four times to shake hands goodbye, sometimes the server's ACK, FIN will be sent at the same time, then the client has no fin_wait_2 state
Directly into the TIME_WAIT state;

The necessity of 3:time_wait existence
Some people will be surprised, the client side send the last Ack, can not become a closed state, why wait until 2MSL time.
If the last ACK is lost, the passive shutdown side will send its fin again. The active shutdown party must maintain a valid state information (maintained in the timewait state) so that the ACK can be sent again. If the active closed socket does not maintain this state and enters the closed state, the active closed socket will respond to a RST after receiving the fin when it is in the closed state. A passive shutdown can be considered an error after receiving the RST. If the TCP protocol wants to complete the necessary operation and terminate the data stream transmission of the two parties, it must transmit the four sections of the four handshake completely correctly without any loss. This is the first reason why the socket is still in the TIME_WAIT state after it is closed, because he has to wait for the ACK to be sent back.
Suppose that both sides of the current connected communication have called close (), both sides enter the closed end state without going time_wait. There is a problem with a new connection that is now established with the same IP address and the same port as the previous one, and the connection that was established is a full reuse of the original connection. It is also assumed that the original connection has a datagram remaining in the network, so that a new connection may receive a previously connected datagram in the datagram. To prevent this, TCP does not allow new connections to duplicate sockets in the TIME_WAIT state. The socket in the TIME_WAIT state is turned into a closed state after waiting twice times the MSL time. This means that a successful connection must ensure that the remaining datagrams in the previous network are lost;

4: What is 2MSL. MSL is the maximum Segment Lifetime, which is the maximum lifetime of the message, referenced

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.