UDP Protocol
UDP doesn’t provide complex control mechanisms. It uses IP to offer connectionless communication service. It takes data from applications the moment it arrives and immediately sends it to the network as-is.
Even when networks become congested, UDP can’t do flow control to avoid congestion. During transmission, if packets get lost, UDP won’t retransmit them. If packets arrive out of order, UDP has no correction mechanism.
IPv4 Header | UDP Header | UDP Data
20 bytes | 8 bytes |UDP Header:
- Source port: 2 bytes
- Destination port: 2 bytes
- Length: 2 bytes
- Checksum: 2 bytes
TCP vs UDP Differences
Connection model: TCP is connection-oriented (like making a phone call that requires dialing first). UDP is connectionless—no need to establish connections before sending data.
Reliability: TCP provides reliable service. Data sent through TCP connections has no errors, losses, or duplicates, and arrives in order. UDP delivers best-effort only—it doesn’t guarantee reliable delivery.
Data handling: TCP treats data as byte streams—essentially viewing data as an unstructured sequence of bytes. UDP is message-oriented.
Congestion control: UDP has no congestion control. When networks become congested, source hosts don’t reduce transmission rates (this helps real-time applications like VoIP and video conferencing).
Communication patterns: Each TCP connection must be point-to-point. UDP supports one-to-one, one-to-many, many-to-one, and many-to-many communication.
Overhead: TCP headers cost 20 bytes. UDP headers are small—only 8 bytes.
Channel type: TCP’s logical communication channel is full-duplex and reliable. UDP channels are unreliable.
UDP has boundaries. Applications must receive entire packets at once. You can only receive one packet per read operation. Each reception either gives you a complete, independent data packet or nothing at all.
UDP Reliable Transmission
Applications must ensure reliability:
- Add sequence numbers
- Implement timeout retransmission
- Use acknowledgment confirmations
- Apply sliding window flow control
Applications
DNS uses TCP for zone transfers but uses UDP for other operations.
Port Binding
TCP and UDP can bind to the same port because they’re separate modules in the kernel protocol stack. Their port numbers operate independently.