当前位置:网站首页>Explain TCP protocol in detail three handshakes and four waves
Explain TCP protocol in detail three handshakes and four waves
2022-07-04 08:52:00 【Java mage】
Three handshakes :
Three handshakes indicate the establishment of communication phase , stay TCP Agreement , In the preparation stage of sending data , Three interactions between client and server , To ensure reliable connection , Because of this connection oriented feature , TCP Protocol can ensure the security of data transmission , So it's widely used . For example, uploading files 、 Download the file 、 Browse the web, etc
The first handshake , Client sends connection request to server , Wait for server to confirm ( customer : I just can't get in )
The second handshake , The server sends a response back to the client , Notify client that a connection request has been received ( clothing : That's ok )
The third handshake , The client sends the confirmation information to the server again , Confirm connection Complete three handshakes , After the connection is established , The client and server can start data transmission .( customer : Here we go )
name | meaning |
---|---|
SYN(synchronous) | Establishing a connection |
ACK(acknowledgement) | Connect to confirm |
PSH(push) | delivery |
FIN(finish) | end |
RST(reset) | Reset |
URG(urgent) | emergency |
Sequence number | Sequence number |
Acknowledge number | Confirmation number |
Establishing a connection ( Three handshakes ) The process of :
- The client sends a
SYN
logo TCP Message to server . This is the segment in the process of three handshakes in the above figure 1. Client issue SYN Bit indicates connection request . The serial number is 1000, This serial number is used as a temporary address in network communication , Every data byte sent , This serial number needs to be added 1, In this way, the correct sequence of data packets can be arranged according to the sequence number at the receiving end , Packet loss can also be found . in addition , Regulations SYN Bit and FIN Bit should also occupy a serial number , Although no data was sent this time , But because of SYN position , Therefore, the next time you send it, you should use the serial number 1001.mss Indicates the maximum segment size , If a segment is too large , The maximum length of the link layer is exceeded after being encapsulated into a frame , Must be in IP Layering , To avoid that , The client declares its maximum segment size , It is recommended that the length of the segment sent from the server should not exceed this length .- The server responds to the client , It's the third handshake 2 Message segments , With
ACK
Logo andSYN
sign . Means to the client just now SYN The response of the ; At the same time SYN To the client , Ask if the client is ready for data communication . The server sends out a segment 2, It also has SYN position , Simultaneous placement ACK Bits indicate confirmation , Confirm that the serial number is 1001, Express “ I received the serial number 1000 And all previous paragraphs , Please send next time the serial number is 1001 Section of ”, That is, the connection request of the client is answered , It also sends a connection request to the client , At the same time, it is declared that the maximum size is 1024.- The client must respond to a server-side request again ACK message , This is a message segment 3.
The client sends out a segment 3, Answer the connection request of the server , Confirm that the serial number is 8001. In the process , The client and server send connection requests to each other , Also answered the other party's connection request , The server's request and response are sent in one segment . Therefore, there are three segments for establishing a connection , be called “ Three party handshake ”. While establishing the connection , The two sides negotiated some information , for example , Both parties send the initial value of the serial number 、 Maximum segment size, etc .
The process of data transmission :
- The client sends out a segment 4, Contains the slave serial number 1001 At the beginning 20 Bytes of data .
- The server sends out a segment 5, Confirm serial number is 1021, The serial number is 1001-1020 The data indicates confirmation of receipt , At the same time, request to send serial number 1021 Starting data , While answering, the server also sends the slave serial number to the client 8001 At the beginning 10 Bytes of data .
- The client sends out a segment 6, The serial number sent to the server is 8001-8010 The data indicates confirmation of receipt , Request to send sequence number 8011 Starting data .
In the process of data transmission ,ACK And confirming the serial number is very important , The application is handed over to TCP The data sent by the protocol will temporarily exist TCP In the send buffer of layer , After sending the packet to the other party , Only those who receive an answer ACK The segment knows that the packet has indeed been sent to the other party , It can be released from the send buffer , If the packet is lost due to network failure or the packet sent back by the other party is lost ACK paragraph , After waiting timeout TCP The protocol automatically retransmits packets in the sending buffer .
Four waves :
Four waves (Four-Way-Wavehand) Termination TCP Connect , To disconnect one TCP When the connection , The client and server are required to send in total 4 Packages to confirm disconnection . stay socket Programming , This process is performed by either the client or the server close To trigger .
The client sends a request to the server to cancel the connection
The server returns a response to the client , Indicates that a request has been received
The server sends a confirmation cancellation request to the client
The client reconfirms that the connection is cancelled
Why only shake hands three times , It takes four waves
Because the two ends are not connected when shaking hands , Just confirm the connection
But when waving, it is already connected , At this time, the server should process the final data after the second handshake , After processing the final data, confirm with the client before canceling
Close the connection ( Four handshakes ) The process of :
because TCP Connection is full duplex , Therefore, each direction must be closed separately . This principle is that when a party completes its data transmission task, it can send a FIN To terminate the connection in this direction . Receive a FIN It just means there's no data flow in this direction , One TCP Connect to receive a FIN Can still send data after . Active shutdown will be performed by the first party to close , And the other party performs a passive shutdown .
- The client sends out a segment 7,FIN Bit indicates the request to close the connection .
- The server sends out a segment 8, Answer the client's request to close the connection .( Here is a half closed state )
- The server sends out a segment 9, It also includes FIN position , Send a close connection request to the client .
- The client sends out a segment 10, Answer the server's request to close the connection .
The process of establishing a connection is three handshakes , Closing the connection usually requires 4 Segments , The server's reply and close connection request are usually not combined in one segment , Because the connection is half closed , In this case, after the client closes the connection, it can no longer send data to the server , But the server can also send data to the client , Until the server also closes the connection .
边栏推荐
- awk从入门到入土(6)正则匹配
- Codeforces Round #793 (Div. 2)(A-D)
- 老掉牙的 synchronized 锁优化,一次给你讲清楚!
- 广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
- C語言-入門-基礎-語法-[運算符,類型轉換](六)
- 微服务入门:Gateway网关
- 1211 or chicken and rabbit in the same cage
- Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
- AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
- What if I forget the router password
猜你喜欢
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
Manjaro install wechat
Awk from entry to earth (12) awk can also write scripts to replace the shell
到底什么才是DaaS数据即服务?别再被其他DaaS概念给误导了
DM8 tablespace backup and recovery
Clion console output Chinese garbled code
C language - Introduction - Foundation - syntax - [identifier, keyword, semicolon, space, comment, input and output] (III)
C语言-入门-基础-语法-[运算符,类型转换](六)
The basic syntax of mermaid in typera
Leetcode topic [array] -136- numbers that appear only once
随机推荐
微服务入门:Gateway网关
Comparison between sentinel and hystrix
What exactly is DAAS data as a service? Don't be misled by other DAAS concepts
Three paradigms of database design
Codeforces Round #803 (Div. 2)(A-D)
There are 100 people eating 100 apples, one adult eating 4 apples, and four children eating 1 apple. How can they eat exactly 100 apples? Use any high-level language you are familiar with
manjaro安装微信
Ehrlich sieve + Euler sieve + interval sieve
What if I forget the router password
Xcode 6 swift code completion does not work properly - Xcode 6 swift code completion not working
Fault analysis | MySQL: unique key constraint failure
awk从入门到入土(14)awk输出重定向
Awk from entry to earth (15) awk executes external commands
[Chongqing Guangdong education] National Open University spring 2019 455 logistics practice reference questions
Codeforces Global Round 21(A-E)
ctfshow web255 web 256 web257
Horizon sunrise X3 PI (I) first boot details
Educational Codeforces Round 119 (Rated for Div. 2)
Newh3c - routing protocol (RIP, OSPF)
Awk from entry to soil (5) simple condition matching