Easy-to-understand three-way handshake and four-way wave

1. This article helps everyone understand the three-way handshake and four-way wave of the TCP protocol in an easy-to-understand way;

2. First look at the basic name;

     SYN: synchronous connection sequence number, SYN=1 (request to establish connection);
     ACK: request/response status, ACK=0 (request status), ACK=1 (response status);
     FIN: end connection, FIN=0 (end connection line request), FIN=1 (end connection).

3. Introduce the understanding of "three-way handshake" through warm-up stories;

Warm-up:

TCP's three-way handshake is a bit like the traditional virtues of the Chinese nation - reciprocity;

1) a gives b an iPhone (first handshake a->b);

2) After b received it, he was very happy, kept saying thank you, and in return, gave a an Apple computer (second handshake b->a);

3) After a receives b’s return gift, he tells b that he received it and says thank you to b (third handshake a->b);

A complete gift giving process.

Understanding:

1) The client sends a connection request to the server (sends a SYN packet and enters the SYN-SEND state) (first handshake);

2) After receiving the connection request, the server agrees to establish a connection with the client (sends an ACK-SYN packet and enters the SYN-RCVD state) (second handshake);

3) After receiving the consent from the server, the client confirms the establishment of the connection with the server (third handshake).

The client and server have established a connection and can transmit data.

 

4. Introduce the understanding of "four waves" through warm-up stories;

Warm-up:

TCP's four waves - break up with the scumbag;

Brief description of the story: C and D are boyfriend and girlfriend. One day, C discovers that D is a scumbag and wants to break up with D;

1) c proposes a breakup request to d (waves for the first time);

2) After d received the request, although d was a scumbag, d was still very polite and told c that I received your request; but I am busy dating other people now (waving for the second time);

3) D is finally free and tells C that I accept your request to break up (waving for the third time);

4) After c received d’s reply, he told d that I was finally free (waving for the fourth time).

Understanding:

1) The client sends a disconnection request to the server (FIN=1, enters FIN-WAIT-1 state) (waves for the first time);

2) After receiving the disconnection request, the server agrees to disconnect from the client, but there is still data being transmitted and needs to wait for the data to be transmitted first, so it first informs the client that it has received the disconnection request (enters the CLOSE-WAIT state ) (waving for the second time);

3) After the server data transmission is completed, notify the client that the connection is to be closed (wave for the third time);

4) After receiving the disconnection message from the server, the client informs the server that the disconnection message has been received (the fourth wave);

The client and server close the connection.

5. The above is just to facilitate non-professionals’ understanding of TCP’s three-way handshake and four-way wave;

Guess you like

Origin blog.csdn.net/qq_42676363/article/details/106758628