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
Two years ago, 5G was still far away from us; two...
After the Spring Festival of the Year of the Ox, ...
RAKsmart offers a series of promotional products ...
From September 22 to September 23, the 2016 Tence...
HostYun also offers VPS hosts in Hong Kong Equini...
Smart home connections include not only familiar ...
Private 5G is the next evolution of networks for ...
Telecom operators are investing in operator softw...
HTTP is a stateless protocol, that is, each time ...
[[437603]] If you follow current events, you’ve p...
Improve your chat style and enter the IoT circle ...
[[427165]] Learn more about BeautifulSoup Scrapin...
RAKsmart launched a flash sale promotion for new ...
Service mesh adoption continues to grow, and some...
Clouvider is a foreign hosting company founded in...