TCP three-way handshake and four-way wave (humor version)

Three-way handshake:


Suppose you are a bird and you want to communicate with another bird. (you are the client)

1. First you will greet: "Hi, I'm a bird, can you hear me?" (one session)

2. Another bird replies: "Yes, I can hear you, I'm a bird too." (Two sessions)

3. You say again: "Very good, I think we can start talking." (Three sessions)



Formal answer:

The three-way handshake in a computer network is a process that uses the TCP protocol to ensure that the two parties in communication establish a reliable connection. Its specific steps are as follows:

First handshake (SYN sending) : The client sends a SYN (Synchronize Sequence Numbers) flag bit to the server, requesting to establish a connection and inform the server of its initial sequence number (ISN).

The second handshake (SYN-ACK response) : After receiving the SYN flag from the client, the server returns a SYN-ACK (Synchronize-Acknowledgment, synchronization confirmation) flag, indicating that it agrees to establish a connection and informs itself of its initial sequence number.

The third handshake (ACK sending) : After receiving the SYN-ACK flag from the server, the client sends an ACK (Acknowledgment) flag to the server, indicating that the SYN-ACK from the server has been received and the connection is successfully established.

In this way, in the process of the third handshake, the client and the server can confirm each other's status and establish a reliable connection for data transmission and communication. If any party makes an error during the three-way handshake, the connection will fail, and both parties need to re-initiate the handshake connection.


Wave four times:

It’s like breaking up with men and women. Boys say they want to break up (first wave), girls agree and say they want to break up (second wave), boys accept the breakup after receiving the girl’s message (third wave), girls After receiving the news, the two parties broke up and ended (the fourth wave).



1. Initial state: Client and Server establish a connection, and Client sends a FIN message, indicating that it wants to close the connection.
2. The first wave: After receiving the FIN message, the Server sends an ACK message, indicating that it has received the Client's request, and tells the Client that it will also close the connection.
3. Second wave: Server sends a FIN message, indicating that it is ready to close the connection.
4. The third wave: After receiving the FIN message from the server, the client sends an ACK message, indicating that it has received the request from the server, and tells the server that it is also ready to close the connection.
5. End of state: After the server receives the ACK message, the two parties disconnect.


Why is the waiting time of TIME_WAIT 2MSL?

The main reason is to ensure that the first ACK message sent by the client can reach the server, because this ACK message may be lost, and 2MSL is the longest time for any message to exist on the network. is discarded, so that the request message of the old connection will not appear in the new connection.

Have you learned in front of the screen?

 

Guess you like

Origin blog.csdn.net/m0_62600503/article/details/130892048