UDP协议(RFC768)

UDP协议是一种无连接(connectless)的通信协议,UDP协议需要与IP协议配合使用。

简介

UDP适合不需要进行错误检查和更正的场景,或者交由应用层来完成错误检查工作,UDP能够在协议栈上避免对这部分功能过度操作。对于延迟比较敏感的程序通常使用UDP作为通信协议,相比于重新传输带来的延迟,丢包是可以接受的。

协议规格

UDP协议的格式如下图所示

nil

Source Port is an optional field, when meaningful, it indicates the port of the sending process, and may be assumed to be the port to which a reply should be addressed in the absence of any other information. If not used, a value of zero is inserted.

Destination Port has a meaning within the context of a particular internet destination address.

Length is the length in octets of this user datagram including thisheader and the data. (This means the minimum value of the length is eight.)

UDP的校验码的计算逻辑与TCP的相同。
Checksum is the 16-bit one’s complement of the one’s complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets. This checksum procedure is the same as is used in TCP.

UDP协议在IP协议中的协议号为17。
This is protocol 17 (21 octal) when used in the Internet Protocol.

Comments

Comments powered by Disqus