当前位置:网站首页>Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?

Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?

2022-07-06 00:37:00 InfoQ

Hello , This is the network technology alliance station .

TCP yes  Internet  One of the main protocols of the protocol suite , It lies between the application layer and the network layer , Used to provide reliable connection services , It's a connection oriented communication protocol , It helps to exchange messages between different devices through the network .

mention TCP, Then it must be mentioned TCP Three handshakes of , This is TCP Connect the core in the core , that TCP What is the process of three handshakes , What is the outstanding design ?

Today, Rego will show you a good explanation in the form of diagrams , Let's go straight to .

What is? TCP?

  • English full name :
    Transmission Control Protocol
  • Chinese name :
    Transmission control protocol

null
TCP It's a kind of
Connection oriented
The agreement , It can ensure the complete transmission of data to its destination ,TCP  First by using  TCP  Three way handshake with each host  TCP  port
Establish a conversation
, Then... With it
Data packets
In the form of data transmission , Each packet has one
Serial number
, When a packet is received at the destination ,TCP  Will be generated to the sending host
confirm
, If the packet in the sequence is not received , Then send the  TCP  After a certain time interval
Retransmission
Data packets .

TCP Three handshakes

TCP  During the establishment and closing of the connection between two devices  3  The handshake process , That is, establishing and closing connections requires three steps , Now let's have a detailed understanding of these three processes .

Three handshakes in life

Let's first illustrate the process of three handshakes with examples in life :

null
Xiao Ming wants to call Xiaomei , But I'm not sure whether the other party is Xiaomei , So I will go through the following process :

  • Xiao Ming : Hello , Is it Xiaomei ?【
    The first handshake
  • Xiaomei : Yes , I'm Xiaomei .【
    The second handshake
  • Xiao Ming : well , I know you are Xiaomei .【
    The third handshake

After three handshakes , Xiao Ming can clearly confirm that the other party is Xiaomei , very
reliable

If there is only one handshake
, Then Xiao Ming finished asking “ Hello , Is it Xiaomei ?”, Xiao Ming is not sure whether the other party has received this greeting , Not to mention whether the other party is Xiaomei .

If only two handshakes
, Then Xiao Ming received Xiaomei's “ Yes , I'm Xiaomei .” After the reply , Xiaomei doesn't know whether Xiaoming has received her reply , So next, she was not sure whether to communicate with the person who asked her on the phone .

So three handshakes are just right .

Three professional handshakes

Now let's look at three professional handshakes .

Professional terms involved in three handshakes

  • Server side
    : The server is a physical computer dedicated to running services to meet the needs of other computers

null
  • client
    : The client is the computer hardware device or software that accesses the services provided by the server
  • SYN
    : Sync serial number (Synchronize Sequence Number), This is the first packet from the client to the server , It can be described as a request to establish a connection , If  SYN  by  1, It means that the device needs to establish a secure connection , Otherwise not .

null
  • ACK
    : confirm (Acknowledgement), Can be said to be SYN Response , If  ACK  by  1, The device has received  SYN  Message and confirm , Otherwise no .

null
Three handshake steps

null
First step
: The client will  SYN  Flag set to  1  Send the message to the server .

The second step
: The server passes  ACK  Flag set to  1  To confirm the client request .

The third step
: The client receives synchronization from the server (SYN) after , Send confirmation to the server (ACK).

Get... From the client (ACK) after , Establish a connection between the client and the server , Now data can be transferred between client and server .

More detailed process

null
  • First step :TCP The client sends... To the server  TCP SYN  Packets to start the connection , The packet contains a random serial number n, It represents the serial number of the data that the client should transmit
    Start
    .

null
  • The second step : The server receives the packet , And use its serial number (m) To respond , Its response also includes the confirmation number , That is, the serial number of the client plus  1, Here is n+1.

null
  • The third step : The client responds to the server by sending a confirmation number , The confirmation number is the serial number of the server plus  1, Here is m+1.

null

TCP Analysis of three handshakes

No amount of theory is in vain without practice , So the best way to verify our theory is to grab the bag and have a look TCP Three handshake process .

null
Pictured , host
172.16.16.128:2826
And host
212.58.226.142:80
Establish three handshake processes :

  • First step : host
    172.16.16.128:2826
    Host computer
    212.58.226.142:80
    send out [SYN] Seq=0
  • The second step : host
    212.58.226.142:80
    Host computer
    172.16.16.128:2826
    send out [SYN,ACK] Seq=0,Ack=1
  • The third step : host
    172.16.16.128:2826
    Host computer
    212.58.226.142:80
    send out [ACK] Seq=1,Ack=1

This is the detailed three handshake message , I think at this moment , You can open your own wireshark Experience the bag grabbing tool to your heart's content TCP The magic of three handshakes .

TCP window

Everyone is looking at the wireshark When capturing screenshots , I must have noticed
Win=8192
Wording , This is TCP window .

The client sends a pile of data to the server , Then the server verifies the checksum of all packet levels and sends a ACK Data packets , It indicates that all data has been received correctly .

If you don't receive everything , You need to retransmit some or all of the data , Each device maintains a buffer for all data , In case you need to send it again , Received  ACK  Packets mean that the device can clear old data from the buffer .

null
TCP  window
Is receiving  ACK  The maximum number of bytes that can be sent before .

If the network is unreliable , It is best to TCP  Make the window smaller , such , If something goes wrong , There is no need to retransmit very large data .

TCP There is also a great design , That's it
The sliding window
, That is, the device can
dynamic
Change window size , Narrow the window in case of congestion , Enlarge the window when normal .

The other parameters

There are more than TCP  window , There are other parameters :

  • MSS
     (Maximum Segment Size), Maximum segment size .
  • WS
     (Windows Scaling), Used to control the maximum  TCP  Receive window size .

TCP Why can't a second handshake establish a connection

We need to know Server  and  Client  Want to establish a connection , The following four conditions must be met :

  • The server needs to confirm that the server can receive packets from the client
  • The client needs to confirm that the client can receive packets from the server
  • The client needs to confirm that the server can receive packets from the client
  • The server needs to confirm that the client can receive packets from the server

The four conditions seem very convoluted , In fact, it's just :

null
  • Xiaoming asked :“ Hello , Excuse me, Shi Xiaomei ?”: After sending successfully , Xiaoming is sure that he can receive information from Xiaomei , The first condition is verified 【
    The server needs to confirm that the server can receive packets from the client
  • Xiaomeihui :“ Yes , I'm Xiaomei ”: After sending successfully , Xiaomei is sure that she can receive information from Xiaoming , It can also confirm that Xiao Ming can receive information from her , Verified the second 、 The third condition 【
    The client needs to confirm that the client can receive packets from the server
    】【
    The client needs to confirm that the server can receive packets from the client
  • Xiaoming returns :“ well , I know you are Xiaomei ”: After sending successfully , Xiaoming is sure that Xiaomei can receive information from him , Four conditions are verified 【
    The server needs to confirm that the client can receive packets from the server

TCP  It is a two-way communication protocol , This means that either end should be able to send data reliably , So three handshakes are just right .

summary

TCP 3  This handshake is used to create a secure and reliable communication connection , This article combines examples in life , Vividly explained the process of three handshakes , The main contents are as follows :

  • What is? TCP?
  • TCP Three handshakes
  • Three handshakes in life
  • Three professional handshakes
  • TCP Analysis of three handshakes
  • TCP window
  • The other parameters
  • TCP Why can't a second handshake establish a connection
  • 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/187/202207060033007181.html