Computer Network (10)-Simple and easy to use UDP

The UDP protocol is one of the two important protocols in the transport layer. It has a simple structure and provides unreliable transmission. It is suitable for short message and real-time data transmission. If it is said that TCP is used to kill chickens, then UDP is the best alternative strategy.

1. UDP features

​ 1) Connectionless transmission, less overhead and delay

​ 2) Best-effort delivery, reliable delivery is not guaranteed

​ 3) Message-oriented, not segmented, suitable for the transmission of a small amount of data

​ 4) No congestion control, suitable for real-time applications

2. UDP header structure

UDP_head

The header of UDP is very simple, a total of eight bytes: 2 bytes source port number, 2 bytes destination port number, 2 bytes UDP data part length, 2 bytes checksum.

The data part of UDP is the application data passed down from the network layer, such as the short message that QQ software needs to transmit, the video data that Douyu video needs to transmit, etc.

Three, UDP checksum

The only thing worth mentioning about the UDP protocol is the UDP checksum, which introduces the concept of a pseudo header.

Pseudo header: a total of 12 bytes, consisting of 4 bytes source IP address, 4 bytes destination IP address, 1 byte all 0s, 1 byte protocol number (17), 2 bytes UDP length

The verification rule is: align the 12 bytes of the pseudo header with the 12 bytes of the UDP header and the data part of the UDP two bytes by two bytes, then add the inverted code and add the inverted code of the result of the addition. The UDP checksum is obtained.

Guess you like

Origin blog.csdn.net/weixin_44580146/article/details/106938784
Recommended