The Art of CommunicationWhat 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 handshakeIn 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 HandshakeWhen 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 handshakeAfter 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 handshakeAfter 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 ToleranceWhy 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. SummarizeIn 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
PS: This article does not involve knowledge about...
SD-WAN technology helps make wide area networks m...
Labs Guide With the development of mobile communi...
[[403376]] This article is reprinted from the WeC...
5G is a new generation of communication technolog...
During HUAWEI CONNECT 2017, Huawei and Microsoft ...
Recently, a technical exchange meeting on Wangsu ...
The Wireless Broadband Alliance (WBA) announced i...
Preface Have you ever had this experience? A larg...
Since the Ministry of Industry and Information Te...
[[424598]] Although major network operators are v...
From low-latency, ultra-high-speed bandwidth to i...
Author: Guo Guanhua, unit: China Mobile Smart Hom...
Nowadays, smartphones have entered the era of ful...