当前位置:网站首页>Graphic network: uncover the principle behind TCP's four waves, combined with the example of boyfriend and girlfriend breaking up, which is easy to understand

Graphic network: uncover the principle behind TCP's four waves, combined with the example of boyfriend and girlfriend breaking up, which is easy to understand

2022-07-08 01:42:00 InfoQ

Hello , This is the network technology alliance station .

In the last section, we illustrated TCP Three handshakes of , Understand the principle of the three handshake process 、 Why do you need three handshakes instead of two to establish a connection , Then shake hands three times when establishing a connection , that TCP How is disconnection broken ?

In this section, , Rego continues to show you the network , Explore TCP The principle behind four waves to disconnect .

Let's go straight to !

TCP A brief review of the three handshakes

TCP  It's a full duplex protocol , To establish a connection , A reliable link can be established through three handshakes :

  • First, the client will send a
    SYN
      news (
    SYNchroniz
    e  Abbreviation ) Indicates that the client wants to establish a connection with the server .
  • The server receives... From the client SYN After the message , reply
    SYN-ACK
    message , Including a SYN Serial number and one ACK Number .
  • The client receives... From the server  SYN-ACK  After the news , Send to server
    ACK
      news .

null

TCP Four waves

Examples in life

Both ends of the connection can be terminated  TCP  Connect , Even unilateral termination is possible , This is also called
Half open connection
, Even if one party has disconnected , The other side can still transmit data .

We said four waves , It means that both parties disconnect .

Let's first explain with examples in life :

null
Xiaomei and Xiaoming are college classmates , When I first went to college , Xiao Ming is tall and handsome , Can also play basketball , Xiaomei adores him very much , Xiao Ming also likes Xiaomei very much , That's it , On a dark night with a high wind , They became lovers .

But over time , Coupled with environmental changes , The two people gradually lost their enthusiasm , So Xiaomei broke up with Xiaoming . The process of breaking up is similar to TCP Four waves :

  • for the first time : Xiaomei said to Xiaoming “ Xiao Ming , Have been together for so long , I don't think we're suitable , Break up ”
  • The second time : Xiao Ming was not too surprised after hearing it , But you can't promise directly , Otherwise, I'll become an iron scum man , So wave your hand for the second time , He said politely “ other , I have something else to say to you , In fact, you are quite good , Not only are people beautiful , Good personality, too , Also reasonable , I study hard , I'm very happy to meet you in College !”
  • third time : Xiao Ming's bilibala is about the same , It's time to show your true face , Then he said to Xiaomei “ Now that you have made up your mind , It's no fun for me to pester you again , Then break up peacefully ~”
  • The fourth time : Xiaomei heard a lot of false words from Xiao Ming , Very angry , Just dumped a “ That's it , Delete each other's wechat , bye !”

Then a big red exclamation mark will appear on Xiaoming's wechat !

null
This is four waves , It's not very image ?

Next time if you forget TCP The steps of four waves , I think you can imagine yourself as a scum man

Okay , Let's get back to business , Let's have a good analysis TCP The principle of four waves .

Analysis of the principle of four waves

null
Pictured , The client wants to disconnect from the server :

  • The client will send a  FIN  news ,
    FIN
      yes  
    FINISH
      Abbreviation ,FIN  The purpose of the message is to make  TCP  Ability to gracefully terminate established connections , Then the client goes into what is called  
    FIN-WAIT  state
    The state of , stay  FIN-WAIT  State, , The client continues to receive messages from the server , And continue to process messages that are already in the queue , But the client will not send any additional data .

This can be associated , Xiaomei is sending the breakup message , Boyfriend Xiaoming has been sending messages to Xiaomei , Xiaomei entered the queue without reading the message , Messages in the queue , Xiaomei will still watch , But I will not take the initiative to reply to these messages .

  • The server sends... To the client ACK news , Confirm that he has received the end message , At this time, the server will no longer accept data from the client .
  • The server can continue to send data to the client ( Finally, tell me something ), If the server has no more data to send , It will also be sent by  FIN  Message to terminate the connection .
  • Then the client sends to the server ACK Confirm that you have received the message of active disconnection from the server .

thus ,TCP Connection is broken !

null
Pictured ,M and N All serial numbers , They represent client and server respectively , It is also to distinguish between the server and the client , Like to see M Just think of the message coming from the client , notice N Just think that the message comes from the server .

So the process becomes :

  • The client sends... To the server
    FIN M
    To the server .
  • The server sends... To the client  
    ACK M+1
    , Client received M+1, I know that the server has received its own Finish news .
  • The server sends... To the client
    FIN N
    The representative is that the server actively sends the end message to the client .
  • The client replies to the server
    ACK N+1
    news , The server sees that it is its own N, So I know that the client also received its own end message .

thus TCP You have successfully disconnected .

Maximum life cycle of disconnection

Here is another example , Xiaomei is finishing sending “ That's it , Delete each other's wechat , bye !” After the news , Will wait at most
Four minutes
, Give Xiao Ming a chance to stay :

null
If in these four minutes , Xiao Ming didn't ask to stay , I'm sorry , It's over completely !Game Over!

stay 【 Analysis of the principle of four waves 】 In the figure , We have noticed TIME_WAIT state , The client sends the last  ACK After paragraph , The connection will not terminate immediately , Because there is no guarantee that the last sent packet has actually arrived , The client or server will initially remain in a time waiting state , until  ACK  Paragraph and any new  FIN  Maximum life cycle of segment (MSL,Maximum Segment Lifetime ) To enter
CLOSED state
.

This mechanism is based on two considerations :

  • Prevent the use of homologous addresses 、 Source port 、 Other of destination address and destination port  TCP  The connection received a delayed data segment .
  • Guarantee TCP The connection was properly closed remotely , That is, wait for the party that passively closes the connection to receive ACK The corresponding message .

summary

this paper , Rego explained to you with vivid examples TCP The process of waving four times , I believe you can understand it as soon as you read it , Then it also analyzes the principle of four waves , Let's take a look at the overview of this article :

  • TCP A brief review of the three handshakes
  • TCP Four waves
  • Examples in life
  • Analysis of the principle of four waves
  • Maximum life cycle of disconnection
  • summary

Thank you for reading , If you think the article will help you , Don't forget to like 、 Collection ! Any questions , Welcome to discuss with me in the comment area below !!!
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/189/202207072358464763.html