当前位置:网站首页>Network knowledge-05 transport layer UDP
Network knowledge-05 transport layer UDP
2022-07-19 07:18:00 【Earth shattering pig worm】
List of articles
1 Transport layer
From the perspective of communication and information processing , The transport layer provides communication services to the application layer above it , It belongs to the highest level of communication oriented part , It's also the bottom layer of user functions .
The transport layer provides logical communication between applications , In other words, it goes to the top ( application layer ) Shielding the details of the lower network layer , Make the application look as if it is transferring data horizontally between the transport layers , But in fact, there is no such actual physical connection between the two .
The transport layer also detects the error of the received message . In the network layer ,IP Detection and field in datagram header , Only detect whether there is an error in the header without detecting the data part .
As long as the transport layer includes connection oriented TCP And unconnected UDP. When the transport layer adopts TCP When the agreement , As soon as possible, the network layer is unreliable , But this logic communication is also equivalent to a full duplex reliable channel . And when it comes to UDP When the agreement , This logical channel is an unreliable channel .
1.1 The main agreement
| agreement | RFC | Data unit | Whether to establish a link | Confirm after receiving the datagram |
|---|---|---|---|---|
| User datagram protocol UDP(User Datagram Protocol) | RFC768 | UDP User datagram | Do not establish a connection | No confirmation is required |
| Transmission control protocol TCP(Transmission Control Protocol) | RFC793 | TCP Message segment | Establishing a connection | Need to confirm |
1.2 Transport layer port
The transport layer passes through the port (protocol port number) It is used to distinguish which application process is using the transport layer to transmit data . in other words , As long as the application process delivers the transmitted message to a destination port of the destination host , The rest of the work ( That is, the process of final delivery ) There is TCP or UDP To complete . Of course , The port specified by an application can be modified , What we are saying is only the default agreement .
The port here refers to the software port , Not the hardware port . for example : personal PC Generally, there is only one network card and one hardware port , But there are many software ports .
TCP/IP The transport layer uses a 16 Bit port number (0~65535) To identify a port , But notice , The port number only has local meaning , The same port number of different computers is not associated ,0 Generally do not use , So... Is allowed 65535 Different port numbers .
attach :TCP/UDP Common port reference
Transport layer ports can be divided into the following two categories .
1.2.1 Port number used by the server
There are two types :
- Be familiar with port number (well-known port number) Or system port number , Values for 0~1023. See
- Registration port number , Values for 1024~49151. This type of port number is not used by applications that are familiar with port numbers . But it must be IANA Register as required , To prevent repetition ( Of course, when it belongs to internal procedures , You don't need to register ).
Here are some common system ports and specified application processes :
| Applications | Default port |
|---|---|
| FTP | 21 |
| TELNET | 23 |
| SMTP | 25 |
| DNS | 53 |
| TFTP | 69 |
| HTTP | 80 |
| SNMP | 161 |
| SNMP(trap) | 162 |
| HTTPS | 443 |
1.2.2 Port number used by the client
The number 49152~65535. This type of port number is dynamically selected only when the client process is running , So it's also called transient port number . When the server process receives a message from the client process , We know the port number used by the client process , So you can send the data to the customer process . After the communication is over , The client slogans that have just been used no longer exist , This port number can be provided to other client processes .
2 User datagram protocol UDP
UDP The agreement IP Reuse is added to the Protocol 、 Separation and error detection function .
2.1 UDP Characteristics
- It's disconnected . Compared with TCP agreement ,UDP The protocol does not need to establish a connection before transmitting data , Of course, there is no release connection .
- It is delivered as best as possible . in other words UDP The protocol cannot guarantee that the data can be delivered to the destination host accurately . There is no need to check the received UDP Message to confirm .
- It's message oriented . in other words UDP The protocol encapsulates the data transmitted from the application layer in a UDP In bag , Do not split or merge . therefore , The transport layer receives the other party's UDP After package , After removing the first part , Leave the data intact to the application process .
- no congestion control . therefore UDP The sending rate of the protocol does not affect the congestion of the network .
- UDP Support one-to-one 、 One to many 、 Many to one and many to many interactive communication .
- UDP The head takes up less , Occupy only 8 Bytes .
2.2 UDP The basic working process of
UDP Encapsulation and unpacking in the transmission of user datagrams

UDP Message transmission queue

UDP Reuse and division of

2.3 UDP Form of agreement
Every UDP The message is divided into UDP Headlines and UDP Two parts of the data area . The newspaper is headed by 4 individual 16 Bit length (2 byte ) Field composition , Respectively describe the source port of the message 、 Destination port 、 Message length and check value .

Real packet capturing results :
2.3.1 Source port
This field occupies UDP Before the header 16 position , Usually contains the... Used by the application that sends the datagram UDP port . The receiving application uses the value of this field as the destination address for sending the response . This field is optional , Therefore, the application program at the sending end does not necessarily write its own port number into this field . If you do not write the port number , Set this field to 0. such , The application at the receiving end cannot send a response .
2.3.2 Destination port
On the receiving computer UDP The port used by the software , occupy 16 position .
2.3.3 length
This field occupies 16 position , Express UDP Datagram length , contain UDP Header and UDP Data length . because UDP The length of the message header is 8 Bytes , So the minimum value is 8.
2.3.4 Check value
This field occupies 16 position , It can check whether the data is damaged during transmission . The check value is pseudo header , Head ,data Three part checksum .
2.3.4.1 Pseudo head
UDP Pseudo header in checksum , Is not UDP Valid data in the message , It's extracted IP Source in datagram IP, Purpose IP Information and data constructed by adding fields such as protocol . Pseudo header in actual network transmission , Only used for checksum calculation , Don't send ! Therefore, it is called pseudo head . In fact TCP Pseudo headers are also used in checksum calculations , And UDP Agreement .

Fake head ( Occupy 12 Bytes ) by :
- 4 Byte source IP Address ;
- 4 The purpose of a byte IP Address ;
- 1 Bytes of 0;
- One byte number 17;
- And occupy 2 Bytes UDP length ;
The checksum performed by the receiver UDP The checksum in the message is consistent with , If there is no mistake, it should be all 1. If there is any mistake , The message is discarded or sent to the application layer 、 And attach error warning .
2.3.4.2 Check sum algorithm
UDP Method and calculation of calculating checksum IP The method of datagram header checksum is similar , The difference is IP The checksum of datagrams only checks IP The header of the datagram , and UDP The checksum of is to check the header and data together .
- First of all, we will put all 0 Write checksum field .
- Put the fake head ,UDP The first one ,UDP The data part is seen as many 16 Bit string . if UDP The data part is not an even number of bytes , Then add 0( But this supplementary byte is not sent ).
- Calculate these by binary inversion 16 The word and .
- Invert the resulting sum , And write the checksum field .

边栏推荐
- Sword finger offer question brushing record - offer 04 Search in two-dimensional array
- TypeScript(ts-loader,tsconfig.json及lodash)
- The use and differences of dictionaries, tuples and lists,
- 函数与随机数
- Closures and decorators
- Sword finger offer question brushing record - offer 07 Rebuild binary tree
- 搭建一个网站都需要那些东西
- Quickly master the sort command and tr command
- IP fragment是什么意思?如何防御IP fragment攻击?
- 爬虫基础—WEB网页基础
猜你喜欢

Fundamentals of crawler - basic principles of agent

WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i

m在VBLAST协作MIMO系统分部使用LDPC,Turbo,卷积三种信道编译码进行误码率matlab仿真

express

How to record enterprise or personal domain names

爬虫基础—WEB网页基础

Paper reading: deep residual learning in spiking neural networks

Data protection / disk array raid protection IP segment 103.103.188 xxx

基于simulink的转速反馈单闭环直流调速系统

m3GPP-LTE通信网络中认知家庭网络Cognitive-femtocell性能matlab仿真
随机推荐
网络知识-03 数据链路层-PPP
m基于matlab的超宽带MIMO雷达对目标的检测仿真,考虑时间反转
保姆级一条龙服务——自关联构造父子级关系(@JsonBackReference和@JsonManagedReference解决循环依赖)
What does IP fragment mean? How to defend against IP fragment attacks?
FreeBSD 12 domestic source speed up PKG and ports take a note
Edit close automatically generate configuration file when saving
爬虫基础—代理的基本原理
Performance test and price comparison of cloud servers of Alibaba cloud, Tencent cloud, Huawei cloud, ucloud and Tianyi cloud
Fundamentals of reptiles - basic principles of reptiles
Classes and objects
Sword finger offer question brushing record - offer 04 Search in two-dimensional array
正则表达式,生成器,迭代器
M design of GPS data longitude and latitude height analysis and Kalman analysis software based on matlab-GUI
听说今天发博客能领徽章!
SNN学习日记——安装SpikingJelly
递归访问目录,打印斐波那契数列,高阶函数
ArraysList方法
m基于matlab的BTS天线设计,带GUI界面
Minecraft integration package [gtnh] gray Technology: new vision server building tutorial
爬虫基础—多线程和多进程的基本原理