Say hello politely - TCP protocol three-way handshake

Say hello politely - TCP protocol three-way handshake

The Art of Communication

What is the most basic and important thing when we communicate with others?

Is it good communication? Is it the right timing? Is it the ability to put yourself in someone else's shoes?

Yes, but not entirely. The first step in communication is of course to say hello politely.

Wait a minute, what are we doing now, popularizing psychology knowledge? This is not our purpose, nor is it our strong point.

We just want to introduce how computers on the network greet each other politely and how the TCP protocol establishes connections.

TCP protocol three-way handshake

In the article "Detailed Explanation of TCP Protocol Messages", the contents of TCP messages have been introduced in detail. So how do hosts establish connections in the TCP protocol?

First, the host that requests to establish a connection is called the client, and the host that is connected is called the server.

First Handshake

When the client requests to establish a connection with the server, it sends a data packet with sequence number j (seq=j) and control bit SYN=1 to the server. At this time, the client status is SYN_SENT.

Second handshake

After receiving the data packet, the server will add an entry for the client's SYN packet (seq=j) in the unconnected queue, indicating that the client's data packet has been received. The server will also send a data packet with sequence number k (seq=k), confirmation number j+1 (ack=j+1), and control bits SYN=1 and ACK=1 to the client, waiting for the client to confirm. At this time, the server status is SYN_RECV.

The third handshake

After the client receives the SYN=1, ACK=1, ack=j+1, seq=k packet from the server, it will respond with an ACK=1, seq=j+1, ack=k+1 packet to the server, indicating that the client has received the server's packet and enters the ESTABLISHED state, indicating that the connection has been established. After the server receives the ACK packet, it deletes the corresponding entry in the unconnected queue and enters the ESTABLISHED state, indicating that the connection has been established.

Retry and Fault Tolerance

Why does the TCP protocol require three handshakes? Is two not enough?

First, assume that only two handshakes are performed, that is, the server establishes a connection immediately after receiving the SYN packet and starts transmitting data. What problems will arise?

If the server receives the SYN data, it will immediately establish a connection for the corresponding client. However, if the client does not receive the ACK packet from the client due to some reasons (such as network interruption, etc.), it will request to re-establish the connection and resend the SYN packet to the server. At this time, the server needs to re-create the connection resources, but the old connection is actually an invalid connection, which wastes system resources. If a large number of clients retry after a long time, it will lead to a serious waste of server resources.

Summarize

In the TCP protocol, a three-way handshake mechanism is used to ensure the reliability of the connection in the Internet. In order to prevent frequent invalid connections and waste of server resources due to connection interruptions, the server maintains an unconnected record table during the first handshake, and deletes the data in the unconnected record table when the connection is successfully established.

<<:  The network protocols behind server push, online gaming, and email

>>:  Say goodbye gracefully - TCP protocol waves four times

Recommend

Let us say goodbye to TCP together!

PS: This article does not involve knowledge about...

Discussion | Technical advantages of the top 9 leading SD-WAN providers abroad

SD-WAN technology helps make wide area networks m...

...

Goodbye 2G, hello 5G

[[403376]] This article is reprinted from the WeC...

What is Wi-Fi 7?

The Wireless Broadband Alliance (WBA) announced i...

Four ways to ensure service availability in the face of traffic bursts

Preface Have you ever had this experience? A larg...

China Radio and Television faces three major challenges on its 5G journey

Since the Ministry of Industry and Information Te...

T-Mobile's 3G network will be shut down on July 1 next year

[[424598]] Although major network operators are v...

5G changes everything. 5G will have a huge impact on many areas of life

From low-latency, ultra-high-speed bandwidth to i...

How to deploy multiple computer rooms? How to synchronize data?

Author: Guo Guanhua, unit: China Mobile Smart Hom...