1, define,

UDP, or User Datagram Protocol, is one of the most important protocols in the transport layer. It is mainly used in audio calls and live broadcasts.

2, the characteristics of

  1. UDP is connectionless. The client and server do not need to establish a connection before UDP communication, which reduces the cost of establishing and releasing a connection.

  2. UDP is delivered to maximum capacity and reliable delivery is not guaranteed. This is just like the everyday phone call scenario, sometimes the signal 📶 is not good, the content of the call may be poor sound quality or even lost, but even if you do not hear clearly, the content of the call will not be played back to you.

3. UDP header

Because of these features, UDP does not need to maintain complex parameters, and its header content is relatively simple, taking up only 8 bytes.

Source port number: used when replying to the destination. Destination port number: used when the destination delivers packets. UDP length: header length + data length.

3.1 CheckSum

Used to check whether UDP datagrams fail during transmission. If an error occurs, the datagram will be discarded.

Verification and calculation method: pseudo head + head + data

One concept mentioned here is the pseudo header. The pseudo header contains more information about the source IP address and destination IP address. The appearance of false headers is mainly to enrich the data and provide more basis for subsequent data inspection. Note that the false header only works when calculating the checksum and is not passed to the upper and lower levels.

3.2 port

The UDP header port occupies two bytes. The port number ranges from 0 to 65535. The following are the ports used by common protocols for communication:

agreement Default port number
HTTP TCP + 80
HTTPS TCP + 443
FTP TCP + 21
MYSQL TCP + 3306
DNS TCP/UDP + 53
SMTP TCP + 25
POP3 TCP + 110

Command for querying the occupied port number (Windows as an example) : netstat -an: displays the occupied port number. Netstat -anb: view occupied ports + applications that occupy ports. Telnet Host port: Check whether a port on a host can be accessed. For example, check whether you can access port 3306 of Baidu through Telnet baidu.com 3306.

4. Packet capture verification

Open the WireShark, access any website, and find UDP packets.

5. Differences between TCP and UDP

TCP UDP
connectivity connection-oriented There is no connection
Reliability Reliable transmission without packet loss Unreliable transmission, best effort delivery, possible packet loss
Bow space occupied Large (20 to 60 bytes) Small (8 bytes)
Transmission rate slow fast
Resource consumption big small
Application scenarios Browser, file transfer, email Audio call, live
Application layer protocol HTTP, HTTPS, FTP, SMTP, DNS DNS