当前位置:网站首页>Three handshake and four wave in tcp
Three handshake and four wave in tcp
2022-08-05 00:59:00 【hgswnsa】
Three handshake
The three-way handshake is the process of establishing a connection
Image
Before a connection is established: The server is in the LISTEN state and the client is in the CLOSED state.
First handshake: The client sends a synchronization segment SYN to the server, and specifies the client's initial serial number ISN. At this time, the client is in SYN_SENT status.
The synchronization bit in the header SYN=1 (SYN is just a flag bit, 0 means not SYN, 1 means SYN), initial serial number seq=x .A segment with SYN=1 cannot carry any data, but a sequence number must be specified.
Second handshake: After the server receives the synchronization segment SYN from the client, it will respond with its own SYN message, and also specify its own initial sequence number ISN, and at the same timeThe client's seq+1 will be used as the value of the confirmation sequence number ack, indicating that it has received the client's synchronization segment SYN, and the server is in the state of SYN_RCVD .
In the confirmation segment SYN=1, ACK=1 (ACK is also just a flag, 0 means notACK, 1 means ACK), initial serial number seq=y , confirmation serial number ack=x+1 , p>
Third handshake: After the client receives the synchronization segment SYN from the server, it will send an acknowledgement segment ACK, using the server's seq+1 as the value of ack, indicating thatI have received the synchronization segment SYN from the server.The client enters the ESTABLISHED state, and the server also enters the ESTABLISHED state after confirming the ACK of the segment.
Confirm the message segment ACK=1, the serial number seq=x+1, confirm the serial number ack=y+1,
At this point, both parties have established a connection and can send data normally.
Why is the three-way handshake three times?

Three handshakes to confirm that both parties are ready
The first handshake: the client can't confirm anything, the server confirms: the other party sends normally, and it receives normally
Second handshake: the client confirms: its own sending and receiving are normal, and the other party's sending and receiving are normal; the server confirms: the other party's sending is normal, and its own receiving is normal
The third handshake: The client confirms: its own sending and receiving are normal, and the other party's sending and receiving are normal; the server confirms: the other party's sending and receiving are normal, and its own sending and receiving are normal.
Four waves
Four waving is the disconnection process
Image
Both the client and the server can actively close the connection, only the first party to request to close will enter the TIME_WAIT state
Before disconnecting: Both client and server are in ESTABLISHED state, both parties can actively disconnect, and the client can actively disconnectIt is better to open the connection.
The first wave: The client intends to disconnect and sends a FIN message to the server. The FIN message will specify a serial number, and then the client enters FIN_WAIT_1 status.
That is, the client sends a connection release segment FIN=1, specifies the serial number seq=u, and actively closesTCP connection, waiting for confirmation from the server.
The second wave: After the server receives the FIN message, it sends an ACK response message to the client, using the client's FIN message sequence number seq+1 as the ACK response messageThe confirmation sequence number ack=u+1 of the segment, and the specified sequence number seq=v.
Then the server enters the CLOSE_WAIT state. At this time, the TCP is in a half-closed state, and the connection between the client and the server is released.After the client receives the ACK response segment from the server, it enters the FIN_WAIT_2 state.
The third wave: The server also intends to disconnect and send a FIN message to the client, after which the server enters the LASK_ACK state, waiting for the clientend confirmation.
In the connection release segment of the server FIN=1, ACK=1, serial number seq=w, confirm the serial number ack=u+1.
Fourth wave: After the client receives the FIN segment from the server, it will send an ACK response segment to the server, and the ACK sequence number ack of the FIN segment is used as the ACKThe sequence number seq of the response segment, and the sequence number seq+1 of the FIN segment is used as the acknowledgment sequence number ack.
After that, the client enters the state of TIME_WAIT. After the server receives the ACK response segment, the server enters the state of CLOSED.At this point, the connection to the server has been closed.
When the client is in the TIME_WAIT state, the TCP has not been released at this time, and it needs to wait for 2MSL before the client enters the CLOSED state.
边栏推荐
- EL定时刷新页面中的皕杰报表实例
- 2022 Nioke Multi-School Training Session 2 J Question Link with Arithmetic Progression
- 数仓4.0(三)------数据仓库系统
- 5.PCIe官方示例
- Software testing interview questions: How many types of software are there?
- The method of freely controlling concurrency in the sync package in GO
- 张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
- Software testing interview questions: What stages should a complete set of tests consist of?
- 配置类总结
- Bit rate vs. resolution, which one is more important?
猜你喜欢
随机推荐
sqlite--nested exception is org.apache.ibatis.exceptions.PersistenceException:
从一次数据库误操作开始了解MySQL日志【bin log、redo log、undo log】
oracle create tablespace
Software Testing Interview Questions: What aspects should be considered when designing test cases, i.e. what aspects should different test cases test against?
Pytorch usage and tricks
跨域解决方案
Software testing interview questions: the difference and connection between black box testing, white box testing, and unit testing, integration testing, system testing, and acceptance testing?
linux(centOs7)部署mysql(8.0.20)数据库
【TA-霜狼_may-《百人计划》】图形4.3 实时阴影介绍
Software test interview questions: BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
MBps与Mbps区别
Software Testing Interview Questions: Qualifying Criteria for Software Acceptance Testing?
【七夕如何根据情侣倾听的音乐进行薅羊毛】背景音乐是否会影响情侣对酒的选择
主库预警日志报错ORA-00270
手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
tensor.nozero(),面具,面具
2022 Hangzhou Electric Power Multi-School Session 3 Question B Boss Rush
2022 Hangzhou Electric Multi-School 1004 Ball
2022 The Third J Question Journey








