当前位置:网站首页>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 
边栏推荐
- Mysql Mac版下载安装教程
- node,npm以及yarn下载安装
- Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
- Separable bonds and convertible bonds
- @Accessors注解作用指定前缀遵守驼峰命名
- Pytorch multi card distributed training distributeddataparallel usage
- Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
- Basic operations of mongodb [add, delete, modify, query]
- Ffmpeg one / more pictures synthetic video
- Applet get user avatar and nickname
猜你喜欢

MongoDB簡介

Use three JS make a simple 3D scene

IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥

Hutool动态添加定时任务

Téléchargement et installation du client Filezilla

900w+ data, from 17s to 300ms, how to operate

node,npm以及yarn下载安装

递归:快速排序,归并排序和堆排序
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions](/img/4a/1df03d9f3315debb4c335260ed39f2.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions

Limit of one question per day
随机推荐
MongoDB简介
File rename
Ansible简介【暂未完成(半成品)】
The XML file generated by labelimg is converted to VOC format
【DRM】DRM bridge驱动调用流程简单分析
Using jasmine to monitor constructors - spying on a constructor using Jasmine
Docker install and start MySQL service
Web会话管理安全问题
没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
Use three JS make a simple 3D scene
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
Pat class B "1104 forever" DFS optimization idea
[embedded module] OLED display module
递归:快速排序,归并排序和堆排序
ffmpeg之 一张/多张图片合成视频
Pytorch轻量级可视化工具wandb(local)