当前位置:网站首页>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
SYNlogo 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
ACKLogo andSYNsign . 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 .
边栏推荐
- Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid
- Bishi blog (13) -- oral arithmetic test app
- C语言-入门-基础-语法-数据类型(四)
- HMS core helps baby bus show high-quality children's digital content to global developers
- The basic syntax of mermaid in typera
- How to choose solid state hard disk and mechanical hard disk in computer
- Four essential material websites for we media people to help you easily create popular models
- 20220701 barbarat lemma proof
- Educational Codeforces Round 119 (Rated for Div. 2)
- Awk from getting started to digging in (4) user defined variables
猜你喜欢

Snipaste convenient screenshot software, which can be copied on the screen

NewH3C——ACL

随机事件的关系与运算

What if I forget the router password

Comparison between sentinel and hystrix

广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网

std::is_ union,std::is_ class,std::integral_ constant

C language - Introduction - Foundation - syntax - data type (4)

ES6 summary

Manjaro install wechat
随机推荐
Ehrlich sieve + Euler sieve + interval sieve
awk从入门到入土(12)awk也可以写脚本,替代shell
Educational Codeforces Round 119 (Rated for Div. 2)
go-zero微服务实战系列(九、极致优化秒杀性能)
Comparison between sentinel and hystrix
How to play dapr without kubernetes?
Awk from entry to soil (5) simple condition matching
随机事件的关系与运算
C language - Introduction - Foundation - syntax - [main function, header file] (II)
DM database password policy and login restriction settings
Bishi blog (13) -- oral arithmetic test app
【无标题】转发最小二乘法
DM8 database recovery based on point in time
Codeforces Round #793 (Div. 2)(A-D)
Turn: excellent managers focus not on mistakes, but on advantages
Fault analysis | MySQL: unique key constraint failure
Awk from entry to earth (8) array
Research Report on the current market situation and development prospects of calcium sulfate whiskers in China (2022 Edition)
埃氏筛+欧拉筛+区间筛
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,Gauss-Jordan消去法,源代码