The UDP Protocol
1. UDP Overview
UDP (User Datagram Protocol) is the connectionless protocol of the transport layer and provides a simple, efficient data transfer service.
Basic Characteristics of UDP
- Connectionless protocol: no connection has to be established beforehand
- Unreliable transmission: it makes no guarantee that packets arrive
- Simple and efficient: small protocol overhead, high transmission efficiency
- Good real-time behaviour: suitable for real-time applications
Where UDP Applies
- Real-time applications: voice and video transmission
- Simple queries: DNS lookups, DHCP
- Games: online games
- Broadcast and multicast: network broadcast
2. The UDP Datagram Structure
The UDP Header Format
UDP Header Format
The UDP header is only 8 bytes: simple and efficient, but it offers no reliability
Field Descriptions
Source port (16 bits):
- The port number of the sending process
- An optional field; set to 0 when it is not used
Destination port (16 bits):
- The port number of the receiving process
- A mandatory field
Length (16 bits):
- The total length of the UDP datagram
- It covers the header and the data
- The minimum value is 8 bytes (the header alone)
Checksum (16 bits):
- Used for error detection
- An optional field; set to 0 when it is not used
- It is computed over the header and the data
Data (variable length):
- Application layer data
- The maximum length is 65507 bytes (65535-20-8)
3. Characteristics of UDP
Advantages
Simple and efficient:
- Small protocol overhead
- Fast processing
- Straightforward implementation
Connectionless:
- No connection has to be established
- There is no waiting when data is sent
- Suitable for bursty traffic
Good real-time behaviour:
- Low latency
- Suitable for real-time applications
- No flow control is performed
Supports broadcast and multicast:
- Supports one-to-many communication
- Suitable for network broadcast
- Supports multicast applications
Disadvantages
Unreliable transmission:
- Makes no guarantee that packets arrive
- Makes no guarantee of the order of arrival
- Makes no guarantee of data integrity
No flow control:
- The receiver’s buffer may overflow
- The sending rate cannot be controlled
- Unsuitable for transferring large volumes of data
No congestion control:
- May make network congestion worse
- Cannot adapt to the state of the network
- Unsuitable in congested environments
4. UDP Applications
DNS (Domain Name System)
- Function: name resolution
- Port: 53
- Characteristic: a simple query with a fast response
- How it works:
- The client sends a DNS query
- The DNS server returns an IP address
- The client caches the result
DHCP (Dynamic Host Configuration Protocol)
- Function: automatic assignment of IP addresses
- Port: 67/68
- Characteristic: broadcast communication, simple and efficient
- How it works:
- The client broadcasts a DHCP discover
- The server offers an IP address
- The client confirms that it will use it
SNMP (Simple Network Management Protocol)
- Function: network management
- Port: 161/162
- Characteristic: simple queries, real-time monitoring
- Application: monitoring network devices
Real-Time Applications
Voice transmission:
- Low latency requirement
- A small amount of packet loss is acceptable
- Real-time behaviour comes first
Video transmission:
- A strong real-time requirement
- Some packet loss is acceptable
- A high bandwidth requirement
Online games:
- Real-time interaction
- Low latency
- Simple and efficient
5. UDP Compared with TCP
| Feature | UDP | TCP |
|---|---|---|
| Connection model | Connectionless | Connection-oriented |
| Reliability | Unreliable | Reliable |
| Flow control | None | Present |
| Congestion control | None | Present |
| Transmission efficiency | High | Lower |
| Latency | Low | Higher |
| Typical use | Real-time applications | Reliable transmission |
| Protocol overhead | Small | Large |
6. UDP Programming
Programming Characteristics
- Simple: the API is simple and easy to use
- Flexible: you can define your own protocol
- Efficient: processing is fast
- Real-time: suitable for real-time applications
Common Applications
- Online games: real-time game traffic
- Streaming media: audio and video transmission
- Network monitoring: device status monitoring
- Simple services: DNS, DHCP, and so on
Exercise 1
What are the main differences between UDP and TCP?
Approach
Compare the two protocols on the dimensions that actually change behaviour in an application: connection model, reliability, flow control, congestion control, efficiency, latency, and typical use.
Steps
- Compare the connection model.
- Compare reliability.
- Compare flow control.
- Compare congestion control.
- Compare transmission efficiency.
- Compare latency.
- Compare the typical scenarios.
Answer
The main differences are:
-
Connection model:
- UDP: connectionless, no connection has to be established beforehand
- TCP: connection-oriented, a connection has to be established first
-
Reliability:
- UDP: unreliable, makes no guarantee that packets arrive
- TCP: reliable, guarantees that data is transferred intact
-
Flow control:
- UDP: no flow control
- TCP: has flow control, which prevents the receiver from being overloaded
-
Congestion control:
- UDP: no congestion control
- TCP: has congestion control and adapts to the state of the network
-
Transmission efficiency:
- UDP: high efficiency, small protocol overhead
- TCP: lower efficiency, large protocol overhead
-
Latency:
- UDP: low latency, suitable for real-time applications
- TCP: higher latency, suitable for reliable transmission
-
Typical use:
- UDP: real-time applications, simple queries
- TCP: file transfer, web browsing
Exercise 2
Which application scenarios suit UDP?
Approach
Group the candidate scenarios by the property that makes UDP the right choice — real-time tolerance for loss, request/response simplicity, or one-to-many delivery — and give a reason for each group.
Steps
- Identify the real-time applications and the loss each can absorb.
- Identify the simple query services and the request/response pattern they use.
- Identify the broadcast and multicast applications.
- Identify the applications with a strong real-time requirement.
- Identify the simple, efficient applications.
Answer
UDP suits the following application scenarios:
-
Real-time applications:
- Voice transmission: latency-sensitive, a small amount of loss is acceptable
- Video transmission: a strong real-time requirement, some loss is acceptable
- Online games: real-time interaction, a low latency requirement
-
Simple query services:
- DNS lookups: simple and fast, one request produces one response
- DHCP: automatic assignment of IP addresses over broadcast
- SNMP: network management and simple monitoring
-
Broadcast and multicast applications:
- Network broadcast: one-to-many communication
- Multicast applications: video conferencing, live streaming
- Service discovery: device discovery services
-
Applications with a strong real-time requirement:
- Online games: real-time interaction
- Streaming media: audio and video transmission
- Network monitoring: device status monitoring
-
Simple, efficient applications:
- Simple protocols: custom protocols
- Lightweight services: simple queries
- Ad hoc communication: one-off data transfers
| Term | Abbreviation | Explanation |
|---|---|---|
| User Datagram Protocol | UDP | Connectionless transport protocol |
| Datagram | - | The protocol data unit of UDP |
| Checksum | - | UDP error detection (optional) |
| Length | - | The total length of a UDP datagram |
| Source port | - | The sender’s port number |
| Destination port | - | The receiver’s port number |
| Connectionless | - | No connection has to be established |
| Unreliable | - | No guarantee of delivery or ordering |
| Low overhead | - | The header is only 8 bytes |
| Real-time application | - | The type of application that suits UDP |
| Domain Name System | DNS | A typical application that uses UDP |
| Dynamic Host Configuration Protocol | DHCP | Uses UDP |
| Simple Network Management Protocol | SNMP | Uses UDP |
| Network Time Protocol | NTP | Uses UDP |
| Voice over IP | VoIP | A real-time application that suits UDP |
