Why does the TCP protocol design a three-way handshake - a condensed version of the latest interview in 2023

Principle: Three-way handshake and four-way handshake mechanism in the TCP protocol

interview:

        OK, interviewer. Regarding this question, I will answer it from the following three aspects.

         1. The TCP protocol is a reliable, byte-stream-based, connection-oriented transport layer protocol. Reliability is reflected in the fact that the data transmission between the two sides of the TCP protocol communication is stable. Even in the case of a bad network, TCP can guarantee data transmission to the target end, and this reliability is realized based on the packet confirmation mechanism. The data transmission between the two sides of TCP communication is connection-oriented through byte stream, which means that before data transmission, a connection must be established, and then data transmission is performed based on this connection.

        2. Because TCP is a connection-oriented protocol, a reliable connection needs to be established before data communication. TCP uses a three-way handshake to establish a connection. The so-called three-way handshake means that the communicating parties need to send a total of three requests to ensure the establishment of the connection. The client sends a connection request to the server and carries the synchronization sequence number SYN. After the server receives the request, it sends SYN and ACK, where SYN means the synchronization serial number of the server, and ACK means a confirmation of the previous request, which means telling the client that I have received your request. After receiving the request from the server, the client sends ACK again. This ACK is a confirmation for the server connection, which means telling the server that I have received your request.

        3. The reason why TCP needs to design a three-way handshake, I think there are three reasons: TCP is a reliable communication protocol, so both parties in the communication of the TCP protocol must maintain a serial number to mark the data packets that have been sent out, which ones are Has been signed by the other party. The three-way handshake is the initial value of the serial number that the communicating parties inform each other. In order to ensure that the serial number is received, both parties need to have a confirmation operation. The TCP protocol needs to achieve reliable data transmission in an unreliable network environment, which means that the communication parties must use some means to achieve a reliable data transmission channel, and three communications are the minimum value for establishing such a channel. Of course, it can be done four or five times, but there is no need to waste this resource. Prevent the confusion caused by repeated connection initialization in history. For example, in the case of a poor network, the client sends multiple consecutive connection establishment requests. Assuming there are only two handshakes, the server can only choose to accept or reject the connection request. , but the server does not know whether this request is a previous request that expired due to network congestion, that is to say, the server does not know whether the current client connection is valid or invalid. The above is my understanding of this issue. 

         The content of network communication is still relatively important. When facing some online network troubleshooting, it can quickly help us locate the problem.

Guess you like

Origin blog.csdn.net/weixin_49171365/article/details/130470432