UDP is a connectionless transport protocol that sends packets without guaranteeing delivery, ordering, or duplicate suppression. Its lower overhead can improve performance when extra reliability is unnecessary, especially on reliable local networks. section 1.2.2 section 6.4.2
Assess these trade-offs before replacing HTTPS over TCP with UDP:
- Accept possible packet loss between client and server. section 6.4.2
- Expect packets to arrive out of order or be routed incorrectly. section 6.4.2
- Recognize that an unencrypted channel permits eavesdropping and data modification. section 6.4.2
- Prefer the trade-off when network reliability and latency requirements outweigh transport-level reliability. section 1.2.2 section 6.4.2
A Python UDP client
Create a datagram socket with socket.socket(socket.AF_INET, socket.SOCK_DGRAM), send serialized requests with sendto(), and receive responses with recv(). A pastebin-style client can encode store and retrieve commands with msgpack, send them to 127.0.0.1:54321, and exchange text identifiers and contents. section 6.4.2
Figure 1.3 API calls via the network stack. Understanding the alternatives available for network communication can dramatically increase the speed of internet-based applications.
Use the network-stack diagram to compare UDP with TCP, HTTP, HTTPS, IP, and lower network layers when selecting a communication path. section 1.2.2




