Skip to content

UDP Protocol

The User Datagram Protocol (UDP) is a simple, connectionless transport protocol that provides best-effort delivery of data. It doesn't handle retransmission of lost or corrupted packets, and packets may arrive in any order.

What is UDP?

UDP is designed for applications that prioritize speed and simplicity over reliability. It sends data packets (called datagrams) directly to the destination without establishing a connection first. UDP doesn't track whether packets arrive, arrive in order, or arrive at all.

UDP Philosophy:

  • Fire and Forget: Send data and don't worry about the result
  • No State: Each datagram is independent
  • Minimal Overhead: Small header, no connection management
  • Best Effort: Network delivers what it can

UDP Header Structure

The UDP header is simple and fixed at 8 bytes, making it much smaller than TCP's 20-60 byte header.

cpp
UDP Header Structure

┌─────────────────────────────────────────────────────────────────────────────┐
│                              UDP Datagram (8 + Payload bytes)               │
├─────────────────┬─────────────────┬─────────────────┬─────────────────────┤
│      Source Port (16 bits)        │      Destination Port (16 bits)        │
├─────────────────┼─────────────────┼─────────────────┼─────────────────────┤
Length (16 bits)                │    Checksum (16 bits) │
├─────────────────────────────────────────────────────────────────────────────┤
Payload (variable)                            │
└─────────────────────────────────────────────────────────────────────────────┘

UDP Header Fields:Source Port (16 bits): Port number of the sending application Destination Port (16 bits): Port number of the receiving application Length (16 bits): Total size of UDP datagram (header + payload) Checksum (16 bits): Optional integrity check (can be zero)

That's really it. You don't need anything else for the protocol to work. The transmission across the network is handled by IP and the delivery to the correct machine is handled by Ethernet. UDP just putters right ahead and sends the data to the correct application on the destination box.

UDP Advantages and Disadvantages

Advantages

Speed:

  • No connection establishment (three-way handshake)
  • No acknowledgment delays
  • Minimal processing overhead
  • Immediate data transmission

Simplicity:

  • Small, fixed header size
  • No connection state to maintain
  • No flow control or congestion control
  • Straightforward implementation

Efficiency:

  • Low CPU usage
  • Low memory footprint
  • No retransmission overhead
  • Suitable for real-time applications

Disadvantages

Unreliability:

  • No delivery guarantees
  • No retransmission of lost packets
  • No error recovery mechanisms
  • Packets may arrive out of order

No Flow Control:

  • Can overwhelm receiver
  • No backpressure mechanism i.e. the receiver can't ask the sender to slow down
  • May cause buffer overflow
  • Receiver must handle data as it arrives

No Congestion Control:

  • Can contribute to network congestion
  • No adaptation to network conditions
  • May cause packet loss for other traffic
  • Network-unfriendly behavior

UDP Multicast

UDP multicast allows one sender to transmit data to multiple receivers simultaneously, making it efficient for applications like video streaming, online gaming, and network discovery.

What is Multicast?

Multicast is a one-to-many communication method where a single packet is delivered to multiple destinations. Unlike broadcast (which goes to all hosts) or unicast (which goes to one host), multicast goes only to hosts that have joined a specific multicast group.

It is important in applications like implementing a sports streaming service or a stock market exchange where the same event has to be broadcasted to all subscribers and the sender doesn't really care if the reciever has been able to collect all packets or not.

In fact, if there was a mechanism to inform the sender if every reciever has been able to collect all packets or not, it would cause significant computational overhead on part of the sender in processing all the responses and will subsequently delay the transmission for everyone!

Questions

Q: What is the UDP philosophy?

UDP follows a 'fire and forget' philosophy. It sends data packets without establishing connections or tracking whether they arrive, arrive in order, or arrive at all.

Q: What is the size of a UDP header?

A UDP header is fixed at 8 bytes, making it much smaller than TCP's 20-60 byte header. This contributes to UDP's speed and efficiency.

Q: Which of the following is NOT a characteristic of UDP?

UDP does not provide flow control. It has no mechanism to prevent overwhelming the receiver or to control transmission rates.

Q: What is UDP multicast?

UDP multicast allows one sender to transmit data to multiple receivers simultaneously, making it efficient for applications like video streaming and network discovery.

Q: Which application typically uses UDP?

DNS queries typically use UDP because they are small, simple requests that need to be fast, and some packet loss is acceptable for name resolution.

Q: What happens when a UDP packet is corrupted?

When a UDP packet is corrupted, it is discarded by the receiver. UDP does not provide retransmission or error recovery mechanisms.

Q: What is the advantage of UDP's stateless nature?

A: Lower memory usage and faster processing

UDP's stateless nature means it doesn't maintain connection state, resulting in lower memory usage and faster processing compared to stateful protocols like TCP.