Three-way handshake and four-way wave humor explanation

By learning the TCP/IP protocol, a personal understanding of the three-way handshake and the four-way wave is described in this humorous way.

The core idea of ​​this agreement is to let me know that you already know it, and say important things three times!

let me know you already know

let me know you already know

let me know you already know

1.Three handshakes

The three-way handshake is the process of establishing a TCP link. The general process is as follows:

The first handshake: This is when the client initiates a connection request to the server, the client sends a friend request (SYN=1) to the server, and talks about chatting for 2 yuan (seq=x)

Second Handshake: Let me know that the core idea you already know starts here. You have to let the client know whether the server has received the request to add you as a friend. The server replies to the client that it agrees to add you as a friend (SYN=1, ACK=1), and replies that you have chatted for 3 yuan (ack=x+1), and returns it to him. Sent a small red envelope (seq=y)

The third handshake: This time the server must know whether the client has received the red envelope from the server. The client will reply to him that I received your red envelope (ack=1), and say that we can chat for 3 yuan ( seq=x+1), and brought back a red envelope (ack=y+1)

This completes the three-way handshake process.

2. Wave four times

Waving four times is the process of disconnecting the TCP connection. The approximate process is as follows:

 Continuing with the last story, after the client and server chatted about 3 yuan, the client found it boring and didn't want to talk anymore.

The first wave: the client told the server that I don’t want to talk to you anymore (FIN), let’s break up.

The second wave: The server received the reply that he knows (ACK) but you have to wait until I finish my work.

Wave for the third time: The server has finished chatting with others. Return to the client. I’m done. I know you don’t want to chat anymore, so let’s break up (FIN)

The fourth wave: The client received this message from the server and was very angry. It threw the ACK to the server and deleted the friend from the server.

So far, the four waves to disconnect the tcp link are over. Isn’t this story a bit like you and your boyfriend/girlfriend, hahaha

3. Why is there a three-way handshake when connecting and four waves when closing?

Because when the server receives the SYN connection request message from the client, it can directly send the SYN+ACK message. The ACK message is used for response, and the SYN message is used for synchronization. But when closing the connection, when the server receives the FIN message, it is likely that the SOCKET will not be closed immediately, so it can only reply with an ACK message first, telling the client, "I received the FIN message you sent." Only when all the messages on my server side have been sent can I send the FIN message, so it cannot be sent together. Therefore, a four-step handshake is required.

This brings us to the story at the beginning. When you add your goddess on WeChat, you first initiate a friend application (the client applies for a link SYN to the server). Your goddess receives your friend application and clicks a confirmation (Confirmation link SYN) The goddess sent it to you and I have added you as a friend (the server sends ACK). After you receive it, reply to the goddess and I saw it (the client sends ACK to the server). In this way, you have established a friend relationship (tcp link established) , so that you can send a message to the goddess Balabala, and you will have a passionate chat from then on.

SYN is used to synchronize ACK to respond

After a period of time, there were differences in your relationship. Suddenly one day you told your goddess that we should break up (the client sent a FIN to the server). After receiving the message, the goddess impatiently replied: "Okay, okay, I understand" (server) Send ACK to the client), I am busy now and will tell you later (the server still has data to process), the goddess is finished and then tells you, you want to break up, right? Let’s break up (the server tells the client Send FIN), your inner anger finally broke out after you received this breakup message, OK, then break up (the client sends ACK to the server), but you did not delete the friend immediately (waiting for a while to prevent network errors and the server did not receive the response from the client) , the server will send FIN again), after a while there is no message, and now you let go of your relationship. . . . . .

4. Why can’t we use two handshakes?

After you add your goddess on WeChat and your goddess agrees, if Tencent's backend doesn't remind you that your friend application has been approved, will you know whether you have added your goddess? Is this the truth?

After the client sends a server connection request, the server replies that the client agrees that the connection can be sent. If the client does not reply with a confirmation message, the server does not know that the client has received the connection consent message from it, which will always occupy the server's resources.

5. What should I do if the client fails after a link is established?

TCP has a keep-alive timer. If the client fails, the server cannot wait forever and waste resources. The server will reset this timer every time it receives a request from the client. The time is usually set to 2 hours. If it has not received any data from the client for two hours, the server will send a detection segment, and every 75 seconds thereafter. Sent every second. If there is still no response after sending 10 probe messages in a row, the server will think that the client is faulty, and then close the connection.
The story follows the previous chapter. This is just like the period when the goddess is in love. The goddess checks in every 2 hours. You send a message to the goddess every day (the client transmits data to the server). The goddess thinks you are still in love with him (reset the tcp keep-alive timer). Once your goddess does not receive your message for more than two hours, your goddess will suspect something wrong with you, so she will call you every 75 seconds (the server sends a detection message to the client every 75 seconds), and she calls you ten times in a row. If you haven’t responded to the phone call, your goddess will think that you don’t love her anymore and you are probably cheating on her, so she dumped you (close link)

This story is so tiring to tell. . . .

If you netizens still don’t understand, tell me and I’ll practice making up stories.

Just kidding, just leave a message if you don’t understand. I’ll see the reply to you, although I may not be able to see it because I don’t see it often. What if an enthusiastic netizen interacts with you? If there is a fate between us, I will see it. , Ha ha ha ha

 

 

Guess you like

Origin blog.csdn.net/qq_44848795/article/details/122412334