Explanation of TCP/IP protocol three-way handshake and four-way disconnection

Source: Internet
Author: User

I. connection-oriented protocols

 

UDP is a connectionless protocol, while TCP is a connection-oriented protocol. The connection-oriented protocol directly establishes a logical connection between two peer intranets.

It ensures that it successfully reaches the receiver by tracking data transmission and confirming and tracking sequence numbers. In short, TCP data transmission is safer than UDP.

 

 

Ii. TCP handshake

 

TCP connection-oriented transmission starts with a handshake between two hosts. Handshaking between one host and another has the following three functions:

1. Ensure the target host is available

2. Make sure the target host is listening on the target port number.

3. The serial number of the sender of the notification to the target host, which can be tracked by both parties during data transmission.

 

 

Iii. TCP data packets

 

A virtual connection is established between TCP hosts through a handshake process. During the handshake, the sequence numbers are exchanged between hosts. when data is sent from one host to another, the sequence numbers are tracked.

TCP converts data to a continuous byte stream, but cannot distinguish the basic message and message boundary of word throttling. After the byte stream is received, the upper-layer application interprets the byte stream as a message.

It can be said that the sender encapsulates data into TCP data packets by protocol, and the receiver also reads data from TCP data packets by protocol.

The maximum value of a TCP packet is 65495 bytes. 65495 = total length-IP header (20 bytes)-TCP Header (20 bytes)

This section describes how to split data and how to add a question header (IP, TCP, and Ethernet) to the data start part ):

(According to the protocol layer, the information encapsulated in the data packet has different names)

 

 

 

4. Establish a TCP connection: three-way handshake

 

1. When a connection is established, the client sends a TCP packet to the server. This packet does not contain any data. Only the client's startup sequence, the destination port number used, and the TCP packet's

The maximum segment size (MSS) also contains a synchronization Identifier-Syn (synchronization sequence number, assuming the SYN value is );

2. The server replies to the startup sequence number and the maximum segment size, that is, first confirm the SYN of the Client: Send an ACK packet, and the value of the ACK packet is (a + 1 );

Then, send a SYN (which contains its own serial number, which is assumed to be B) and define the size of the MSS. Then set the claim bit to acknowledge that the first packet has been received.

3. When the client receives the server serial number and segment size information, it sends an ACK (B + 1) to confirm that it has received the data. The third packet is used to end the handshake process.

(Three handshakes are my preliminary understanding and will be improved in the future)

 

 

5. TCP termination: Four disconnections

 

Why do the three-way handshake is required to establish a connection, and the four-way handshake is required to terminate the connection?

The reason is that the TCP connection is full-duplex, that is, data can be transmitted in both directions at the same time. Therefore, when the TCP connection is closed, it must be closed separately in each direction. This single-direction close is called semi-closed.

The basic process of four disconnections:

(1) When the host completes data transmission, set fin to 1 and request to stop the TCP connection;

(2) Host 2 closes the connection after receiving the fin from the host and sets Ack to 1;

(3) Host 2 initiates a reverse request to terminate the connection and sets fin to 1;

(4) Once the host receives the message, it stops the connection and sets Ack to 1. The dual-direction shutdown ends.

 

 

 

From the above, we can see that there are so many steps to establish and terminate a connection, and finally we know why TCP is slow? However, this improves the reliability of data transmission. Of course, three-way handshakes and four-way disconnections are not clear to me. My understanding is simple and will be improved in the future.

Explanation of TCP/IP protocol three-way handshake and four-way disconnection

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.