当前位置:网站首页>The difference between TCP and UDP, the three handshakes of TCP and the four waves of TCP
The difference between TCP and UDP, the three handshakes of TCP and the four waves of TCP
2022-06-12 15:22:00 【Stars_ min】
One 、 TCP And UDP The difference between
1. The same thing
All belong to the transport layer protocol
2. Difference
| TCP | UDP | |
|---|---|---|
| 1 | Based on connections , High reliability | Based on connectionless , Low reliability |
| 2 | It takes three handshakes 、 Reconfirmation and other processes , Poor real-time , At the same time, the process is complex , Vulnerable to attack | There is no connection , Therefore, the real-time performance is very strong , A little safer |
| 3 | When transmitting data of the same size , Headlines 20 byte , and tcp No packet loss , Costly | When transmitting data of the same size ,udp The first cost is only 8 Bytes , and udp Frequent packet loss , It's a small expense |
| 4 | Every one of them tcp Connections can only be point-to-point | udp Support one-to-one 、 One to many 、 For one more 、 Many to many interactive communication |
| 5 | It's called transmission control protocol , Low transmission efficiency , High reliability | Called user datagram protocol , It is suitable for low reliability transmission , A small amount of data |
Two 、 TCP Three handshakes of
TCP Some nouns need to be explained , To understand
1. A term is used to explain
SYN: Sync serial number , Used to initiate a connection ,SYN=1 Can't carry data , But it consumes a sequence
ACK: Confirm logo , When ACK=1 The confirmation field is valid only when
seq: Serial number , That is, the serial number of the packet itself , Use... For data transmission after connection
ack: Acknowledgement of receipt of a packet , The value is the sequence number of the packet waiting to be accepted ( Is the serial number of the packet that the other party is expected to continue sending )
2. Handshake process


for the first time : client C To the server S Send connection request message , In the header of the message SYN = 1,ACK = 0, Pick a serial number at random seq = i As the initial serial number ,
At this time, the client enters SYN_SEDN Sync sent status .
The second time : The server receives the connection request message from the client , If you agree to establish a connection , Then send a confirmation message , Confirm... In the header of the message SYN = 1 , ACK = 1 ,
ack = i + 1 ,seq = j ( The initial serial number of the server ), here , Server entry SYN_RCVD Sync receive status .
third time : After the client receives the confirmation message from the server , A confirmation message will be sent to the server , Tell the server that it has received its acknowledgement message and is ready to establish a connection , In the header of the confirmation message SYN = 0、
ACK = 1、ack = j + 1、 seq = i + 1. The server receives the client confirmation message , here , Server access ESTABLISHED Connection state established .
3. TCP Why use three handshakes , Instead of shaking hands twice or four times
TCP The purpose of the third handshake is to synchronously connect the serial number and confirmation number of both parties , And exchange TCP Window size information
Why use three handshakes : To prevent invalid request message segments from being accepted by the server , So there's a mistake .
source :TCP Why use three handshakes , Not two or four handshakes
3、 ... and 、 TCP Four waves ( Release )


Active shutdown by one party , The other side closes passively
for the first time : client C Send a FIN, Used to close the client C To the server S Data transfer of , client C Get into FIN-WAIT-1 state
The second time : Server side S received FIN after , Send a ACK To the client C, Confirm that the serial number is the received serial number +1, Server side S Get into CLOSE-WAIT
third time : Server side S Send a FIN, Used to close the server S To client C Data transfer of , Server side S Get into LAST-ACK
The fourth time : client C received FIN after , client C Get into TIME-WAIT state , And then send a ACK To the server S,
Confirm that the serial number is the received serial number +1, Server side S Get into CLOSE state , Complete the fourth wave .
边栏推荐
猜你喜欢

C main function

IMU learning records

Microservice fault tolerance

2021-06-20

广播和多播(TCP/IP详解卷1/2)

Change according to the situation, the road to promotion in the second half of 2022
![[jvm learning] virtual machine stack](/img/64/4942c572f1ae4e4c6e2a6b657660e3.jpg)
[jvm learning] virtual machine stack

Deepin20.6 RTX3080 安装显卡驱动510.60.02、CUDA11.6、PyTorch1.11

ROS 中 boost::bind( ) 的使用

How to set public IP access on the H3C gr5200 router
随机推荐
频繁项集产生强关联规则的过程
Seaborn Brief
[LDA] basic knowledge notes - mainly AE and VAE
org. xml. sax. SAXParseException; lineNumber: 63; columnNumber: 10; The definition of "mapper" in the related type must be matched with "(CAC
Change according to the situation, the road to promotion in the second half of 2022
ssm中的文件上传和下载
odom坐标系的理解
Points chocolate (two points answer) Blue Bridge Cup provincial competition
jupyter notebook新环境快捷方式
Servlet connects to database to realize user login function
xshell 7 官网免费下载
Jupyter notebook new environment shortcut
Is it safe to open an account for flush mobile stock trading
Error 1105: message:\“raft entry is too large
分布式并发重复提交问题
【无标题】
Codeforces Round 797 (Div. 3,CF1690)全题解
Swap numbers, XOR, operator correlation
Simple crawler framework: parsing 51job page position information
Use of boost:: bind() in ROS