
上QQ阅读APP看书,第一时间看更新
Introduction to the UDP protocol
UDP is a protocol that is on the same level as TCP, that is, above the IP layer. It offers a service in disconnected mode to the applications that use it. This protocol is suitable for applications that require efficient communication that doesn't have to worry about packet loss. The typical applications of UDP are internet telephony and video-streaming. The header of a UDP frame is composed of four fields:
- The UDP port of origin
- The UDP destination port
- The length of the UDP message
- The chekSum as the error-control field
The only difference regarding working with TCP in Python is that when creating the socket, you have to use SOCK_DGRAM instead of SOCK_STREAM.
The main difference between TCP and UDP is that UDP is not connection-oriented, this means that there is no guarantee our packets will reach their destinations, and no error notification if a delivery fails.