当前位置:网站首页>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
边栏推荐
- Hutool动态添加定时任务
- ffmpeg下载安装教程及介绍
- Application of derivative in daily question
- [combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
- FileZilla client download and installation
- Yolov5 project based on QT
- Vs 2019 installation and configuration opencv
- [mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
- Mysql Mac版下载安装教程
- Download and install captura and configure ffmpeg in captura
猜你喜欢
navicat 导出数据库的表结构
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
Makefile demo
Don't use the new Dede collection without the updated Dede plug-in
ffmpeg之 一张/多张图片合成视频
The calculation of stripe, kernel and padding in CNN
Recursion: depth first search
Application of derivative in daily question
FileZilla Client下載安裝
node,npm以及yarn下载安装
随机推荐
redis在服务器linux下的启动的相关命令(安装和配置)
Hi3536c v100r001c02spc040 cross compiler installation
Converts a timestamp to a time in the specified format
Convert binary stream to byte array
MongoDB基本操作【增、删、改、查】
可分离债券与可转债
机械臂速成小指南(八):运动学建模(标准DH法)
MongoDB主配置文件
The calculation of stripe, kernel and padding in CNN
Recursion: depth first search
Shardingsphere dynamic data source
MongoDB安装 & 部署
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
FileZilla client download and installation
PHP generates PDF tcpdf
为什么线程崩溃不会导致 JVM 崩溃
递归:深度优先搜索
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
MongoDB简介