Diagram TCP to establish the whole process of connection

Source: Internet
Author: User
Tags ack

TCP is the Transport layer protocol in the Internet, it uses three times handshake protocol to establish the connection, the following is the whole process of TCP establishing the connection.

The process of TCP establishing a connection is shown on the drawing. Assume that host A is a TCP client and B is the server side. The initial TCP processes at both ends are in closed state. In the figure below the host is the state of the TCP process. A is to open the connection actively, B is to open the connection passively.

First A sends the connection request message segment to B, when the sync bit syn=1 in the header, and selects an initial ordinal seq=x. TCP stipulates that the SYN segment cannot carry data, but consumes an ordinal number. At this point, a enters the syn-sent state.

b After receiving the request, send a confirmation to a. In the confirmation segment, the SYN and ACK bits are set to 1, the confirmation number is ack=x+1, and the initial serial number seq=y is also chosen for itself. Note that this segment also does not carry data, but it also consumes an ordinal number. Then B enters the SYN-RCVD state.

A after receiving the confirmation of B, also give a confirmation to B. Confirm the message segment ACK is set to 1, the confirmation number ack=y+1, and its own serial number seq=x+1. At this point, the TCP connection has been established, a enters the established state, and when B receives a confirmation, it also enters the established state.

The above mentioned connection establishment process is often said TCP three times handshake.

Why does a have to send a confirmation? This is mainly to prevent the failure of the connection request message segment suddenly transmitted to B, resulting in errors.

This is how the so-called failed connection request message segment is generated. A sends a connection request, but fails to receive confirmation because the connection request message is missing, so a resend the connection request and establishes the connection after the success. The connection is freed when the data is transferred. It is now assumed that the first request message segment issued by A is not lost, but that a network node has been stranded for a long time so that it is delayed until a certain time after the connection release to arrive at B. Originally this is a long defunct message segment. However, after receiving this invalid connection request segment, B mistakenly thinks that a has sent a new connection request, then sends a confirmation message to a and agrees to establish the connection. If you do not use a handshake of three times, a new connection is established as long as B confirms it.

Because a does not make a request to establish a connection, it ignores the confirmation of B and does not send data to B. But b thought that the new transport links had been established, and had been waiting for a to send the data, so wasted a lot of resources.

The method of TCP three handshake can prevent the above phenomenon from happening. For example, in just the case, the connection will not be established because a does not confirm the confirmation of B. Here's a study questions for everyone: What happens if the message segment in TCP's third handshake is lost?

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.