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

Review: China ranks first in 5G mobile phone sales, is the world happy too?

After the Spring Festival of the Year of the Ox, ...

What is Zigbee? Why is it important for your smart home?

Smart home connections include not only familiar ...

Private 5G and edge computing: a perfect match for manufacturing

Private 5G is the next evolution of networks for ...

Omdia Viewpoint: CNF is key for telecom operators to realize the promise of 5G

Telecom operators are investing in operator softw...

What is the difference between Cookie and Session in HTTP protocol?

HTTP is a stateless protocol, that is, each time ...

How 5G will impact payment processing in 2021 and beyond

[[437603]] If you follow current events, you’ve p...

These 22 IoT terms will make others worship you just by saying any one of them

Improve your chat style and enter the IoT circle ...

Big and small! The little sister tells you everything about BeautifulSoup

[[427165]] Learn more about BeautifulSoup Scrapin...

See all the things a service mesh can do

Service mesh adoption continues to grow, and some...

Clouvider: £3.15/month - 2GB/50GB/5TB@10Gbps/8 data centers available

Clouvider is a foreign hosting company founded in...