UDP 用户数据报协议

  • udp,协议,计算机网络,
  • 2016-05-18 08:07:48

UDP : User Datagram Protocol,用户数据报协议。RFC 文档地址:https://www.ietf.org/rfc/rfc768.txt。UDP 的 RFC 文档很简单,就几页,实际上,UDP 确实也是一个很简单的协议,它建立在 IP 协议之上,是面向数据报(datagram)的不可靠(unreliable)的传输层协议。

IP 协议是一个不可靠的协议,UDP 是建立在 IP 协议之上的一个不可靠协议,为什么有 UDP?

是因为 IP 协议负责的是从一个 IP 地址到另外一个 IP 地址的数据传输,也就是两个主机的通信。但是一般一个主机上运行着多个不同的程序,这些程序都需要与其他主机进行交流,于是我们给每个需要与其他主机进行交流的程序分配一个通信通道,也就是端口。也就是 IP 协议是网络层协议,解决主机到主机的通信,TCP 是传输层协议,解决应用到应用的通信。

UDP 协议很简单,它在每个数据报前面加了四个信息,源端口,目标端口,数据区长度,以及一个校验码。每个字段占用 16 字节。这也是为了端口的范围是从 0 - 65535 的原因,因为 UDP 协议里,用 2 个字节的长度来表示一个端口。

一样是基于不可靠的 IP 协议,TCP 通过很多机制来让它变得可靠,而 UDP 没有添加任何措施来增加传输的可靠性。

协议的 HEADER 部分

              0      7 8     15 16    23 24    31  
             +--------+--------+--------+--------+ 
             |     Source      |   Destination   | 
             |      Port       |      Port       | 
             +--------+--------+--------+--------+ 
             |                 |                 | 
             |     Length      |    Checksum     | 
             +--------+--------+--------+--------+ 
             |                                     
             |          data octets ...            
             +---------------- ...

                  User Datagram Header Format

This User Datagram Protocol (UDP) is defined to make available a datagram mode of packet-switched computer communication in the environment of an interconnected set of computer networks. This protocol assumes that the Internet Protocol (IP) is used as the underlying protocol.

This protocol provides a procedure for application programs to send messages to other programs with a minimum of protocol mechanism. The protocol is transaction oriented, and delivery and duplicate protection are not guaranteed. Applications requiring ordered reliable delivery of streams of data should use the Transmission Control Protocol (TCP) .

文献

相关文章

- EOF -

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动。
转载请注明:文章转载自 Binkery 技术博客 [https://binkery.com]
本文标题: UDP 用户数据报协议
本文地址: https://binkery.com/archives/532.html