当前位置:网站首页>TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
2022-07-03 03:37:00 【Shangwen network】
We know that the commonly used network reference model is TCP/IP Reference model , This reference model is from OSI The reference model evolved , Due to TCP and IP The two protocols are widely used , So it's called TCP/IP Reference model . Now let's learn about the next transport layer protocol TCP as well as UDP
Let's first understand the following TCP agreement :
TCP The protocol is generally a link oriented reliable transmission .
The so-called link oriented means that the following parties will be notified before sending data , For example, I want to send an express to Zhang San , I will call Zhang San first to confirm whether the following party can receive the message , The other party's reply can be received , I will send this express , Reliable transmission refers to the process of transmission ,TCP It will ensure that the other party can receive this information , Note that this integrity refers to the final result , Packet loss is inevitable in the transmission process , But the receiver of packet loss will notify the sender , At this time, the sender will retransmit . For example, the express I just sent to Zhang San may have been damaged or lost for some reasons , Zhang San can inform me , I will send another copy to Zhang San .
that TCP What is the detailed operation process of ?
We will TCP The transmission process of is divided into three parts : Before data transmission 、 In data transmission 、 After data transmission
Before data transmission - Three handshakes
from TCP Connection initiator ( In the figure PC1), Send the first SYN Location 1 Of TCP message . Initial serial number a Generated as a random number , Because I haven't received anything from PC2 Any message , So confirm that the serial number is 0 ;
The receiving party ( In the figure PC2) Received legal SYN After the message , Reply to one SYN and ACK Set up 1 Of TCP message . Initial serial number b Generated as a random number , At the same time, because this message is replied to PC1 Message of , So confirm that the serial number is a+1;
PC1 Received PC2 Sent SYN and ACK In place TCP After the message , Reply to one ACK Set message , Now the serial number is a+1, Make sure the serial number is b+1.PC2 When received ,TCP Two way connection establishment .
The third handshake is to confirm whether the two sides of the communication can receive each other's information , So confirm this thing through three packages .
We can argue that sys It's a bag of inquiry ,ack It is a typical confirmation message
Now let's assume that I want to transfer data to Zhang San , But I won't come up and pass it directly. I need to make sure whether the other party can accept it first , So shake hands three times :
Sys( Can you hear me ?)
Sys+ACK( I can hear you . Can you hear me ?)
ACK( I can hear )
It can be seen that both sides of the three information communications have confirmed that they can receive each other's information , Then you can send data normally .
As for what we see sys hinder seq( Serial number )=a, And the following ACK seq=a+1, It can be considered as a confirmation for pairing. What is the reply of this confirmation message sys
Data transfer process
Data segmentation and reorganization
Ensure that the size of the transmitted data meets the limit requirements of the transmission medium , Ensure that data sent by different applications can be multiplexed in the media
After the segmentation is completed, each segment is transmitted in the network as an independent identity , Then it is possible that the order of arrival is not the order of sending , If it is directly presented to users in this order, there will be a problem of disorder , It's like originally “ my treat ” Send the past because of disordered order and become “ You invited me to dinner ”, This is definitely not going to work , So we'll be TCP Something with a serial number on the header of , Is to identify their order 1、2、3、4. After arriving at the other party, reorganize according to this serial number .
Data confirmation and retransmission
Just now we talked about the function of serial number , In the process of delivery, we may send multiple packets at a time , So how to confirm whether the other party has received data , This is in TCP The reliability of is still very important , At this time, we have Confirmation no. .
Our confirmation number can be called expectation confirmation number , As shown in the figure below , We send two data at a time , These two data serial numbers are 1-1500 and 1501-3000( Be careful : The initial value of the serial number is random ), If the receiver receives both messages , So the confirmation number is 3001, This is the next data that the receiver needs to receive , So it's called expectation confirmation number .
Suppose we 1501-3000 This package was lost in the delivery process, that is, the receiver only received 1-1500, So the confirmation number is 1501, The sender will know that some information has been lost after receiving this confirmation , Then it will 1501 Retransmit to the receiver .
Window size
TCP The data transmission rate is controlled by sliding window mechanism .
- stay TCP Three handshakes to establish a connection , Both sides will pass Window Field tells the other party the maximum number of bytes that the local end can accept ( That's the buffer size ).
- After the connection is established successfully , The sender will announce according to the receiver Window Size sends the corresponding number of bytes of data .
- After receiving the data, the receiver will put it in the buffer , Wait for the upper application to fetch the buffered data . If the data is taken away by the upper layer , The corresponding buffer space will be released .
- The receiver notifies the current acceptable data size according to its own cache space ( Window ).
- The sender is based on the current Window Size sends the corresponding amount of data .
Then we can see from the window size , Both parties guarantee the traffic transmission rate at a mutually acceptable rate through the window size . In fact, some of our common flow control devices will also adjust the window size to affect our communication rate , It's the traffic like downloading that becomes very slow .
attach TCP Header structure , All the fields used above are in the header
After data transmission
After the data transmission is completed, the link needs to be disconnected , The number of links established by each host is limited by , Therefore, the link needs to be disconnected after data transmission .
Fin It can be considered that the transmission here has been completed ,ACK It's still confirmed as usual , But this time it was divided into four times to complete the interaction .
OK,TCP The transmission is complete , that UDP Well ?
UDP The data transfer
UDP It is a connectionless best effort data transmission , The header structure is also particularly simple .
You can see it UDP There is no serial number in the header 、 Confirmation no. 、 Window size and other fields , in other words UDP There is no segmented reorganization as we mentioned above 、 Mechanisms such as retransmission and window size ,UDP Simply present the data to the receiver in a first come first served order , But this also ensures that its advantage is fast .
On the whole TCP The advantage of is reliability ,UDP It's good to be quick , Then when we transmit a traffic, if we pursue reliability, we use TCP, such as : mail 、 Download, etc. . If we transmit a traffic, we pursue speed , Low delay required , Then you can use it UDP, such as : voice 、 video 、 Games etc. .
Join a group to talk about technology , If you have any questions, you can share them directly QQ Group :316317765, You can also pay attention to the next official account. , More information will be released later .
----- Original by Kuige of Shangwen network
边栏推荐
- [AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
- [mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
- npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
- Avec trois. JS fait une scène 3D simple
- Download and install captura and configure ffmpeg in captura
- Pytoch configuration
- Ffmpeg download and installation tutorial and introduction
- 递归使用和多维数组对象变一维数组对象
- The file marked by labelme is converted to yolov5 format
- Convert binary stream to byte array
猜你喜欢
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
ffmpeg之 一张/多张图片合成视频
用Three.js做一个简单的3D场景
Limit of one question per day
umi 路由拦截(简单粗暴)
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
Vs 2019 installation and configuration opencv
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
Ffmpeg recording screen and screenshot
ffmpeg录制屏幕和截屏
随机推荐
Vs 2019 configuration tensorrt
Pat class B "1104 forever" DFS optimization idea
@Accessors注解作用指定前缀遵守驼峰命名
PHP generates PDF tcpdf
The calculation of stripe, kernel and padding in CNN
900w+ data, from 17s to 300ms, how to operate
FileZilla Client下載安裝
Using jasmine to monitor constructors - spying on a constructor using Jasmine
机械臂速成小指南(八):运动学建模(标准DH法)
Yolov5 project based on QT
【学习笔记】seckill-秒杀项目--(11)项目总结
用Three.js做一个简单的3D场景
Bigvision code
LVGL使用心得
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
Change and access of median value of listening object
leetcode:动态规划模板
渤、黄海的潮汐特征
Pat class B common function Usage Summary
redis高级应用【密码防护、数据持久化、主从同步、哨兵模式、事务】【暂未完成(半成品)】