Three handshakes of TCP connections and four disbanding processes-Shen crown

Source: Internet
Author: User
Three-way handshake and four-way disbanding of TCP connections-the Shenshen crown client and the server need to establish a connection through three-way handshake and disconnect the connection through four-way handshake when using a TCP connection to transmit data.

As shown in

Describes the detailed process from TCP connection establishment to Disconnection. The following describes the specific packet details.

In the TCP three-way handshake to establish a connection, the client first sends a request packet with SYN = 1 and Sequence = p to the server.

If the server agrees to authorize the client to this link, it will send a response packet with ACK = p + 1, SYN = 1, Sequence = q.

After the client receives a response packet from the server, it also sends a response packet to the server. the specific content is ACK = q + 1, SYN = 0, Sequence = p + 1.

TCP disconnection requires four handshakes. why not three handshakes? the specific reason is:

When the Server receives the SYN connection request from the Client, it can directly send the SYN + ACK packet. The ACK packet is used for response and the SYN packet is used for synchronization. However, when the connection is closed, when the Server receives the FIN packet, it is likely that the SOCKET is not closed immediately. Therefore, only one ACK packet can be returned to the Client, "I have received your FIN message ". I can send FIN packets only when all the packets on my Server are sent. Therefore, I cannot send them together. Therefore, a four-step handshake is required.

The process of disconnecting is first initiated by the client. First, the client sends a disconnect request packet with FIN = 1 and Sequence = m.

After receiving the request, the server sends a confirmation packet ACK = m + 1 and Sequence = n.

At this time, the client-to-server unilateral connection has been disconnected, and the client will no longer send data packets to the server. The server can still send data to the client. if the server does not need to send data to the client after sending s data packets, the server can send a disconnect request to the client. FIN = 1, Sequence = m + s, ACK = m + 1.

After receiving the server disconnection request, the client sends a confirmation packet. Sequence = m + 1, ACK = m + s + 1;

Note: after the client sends the last ACK packet, it will wait for 2MSL (maximum packet segment survival time) because the packet may be lost in the network, the client waits for 2MSL to worry that the server does not receive the ACK packet and resends the FIN request.

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.