The UDP Protocol

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

Source Port16 bit
Destination Port16 bit
Length16 bit
Checksum16 bit
Datavariable

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:
    1. The client sends a DNS query
    2. The DNS server returns an IP address
    3. 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:
    1. The client broadcasts a DHCP discover
    2. The server offers an IP address
    3. 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

FeatureUDPTCP
Connection modelConnectionlessConnection-oriented
ReliabilityUnreliableReliable
Flow controlNonePresent
Congestion controlNonePresent
Transmission efficiencyHighLower
LatencyLowHigher
Typical useReal-time applicationsReliable transmission
Protocol overheadSmallLarge

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

Exercises

Exercise 1

What are the main differences between UDP and TCP?

udptcpprotocol comparison

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

  1. Compare the connection model.
  2. Compare reliability.
  3. Compare flow control.
  4. Compare congestion control.
  5. Compare transmission efficiency.
  6. Compare latency.
  7. Compare the typical scenarios.

Answer

The main differences are:

  1. Connection model:

    • UDP: connectionless, no connection has to be established beforehand
    • TCP: connection-oriented, a connection has to be established first
  2. Reliability:

    • UDP: unreliable, makes no guarantee that packets arrive
    • TCP: reliable, guarantees that data is transferred intact
  3. Flow control:

    • UDP: no flow control
    • TCP: has flow control, which prevents the receiver from being overloaded
  4. Congestion control:

    • UDP: no congestion control
    • TCP: has congestion control and adapts to the state of the network
  5. Transmission efficiency:

    • UDP: high efficiency, small protocol overhead
    • TCP: lower efficiency, large protocol overhead
  6. Latency:

    • UDP: low latency, suitable for real-time applications
    • TCP: higher latency, suitable for reliable transmission
  7. Typical use:

    • UDP: real-time applications, simple queries
    • TCP: file transfer, web browsing

Exercise 2

Which application scenarios suit UDP?

udpreal-time applicationsprotocol selection

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

  1. Identify the real-time applications and the loss each can absorb.
  2. Identify the simple query services and the request/response pattern they use.
  3. Identify the broadcast and multicast applications.
  4. Identify the applications with a strong real-time requirement.
  5. Identify the simple, efficient applications.

Answer

UDP suits the following application scenarios:

  1. 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
  2. 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
  3. Broadcast and multicast applications:

    • Network broadcast: one-to-many communication
    • Multicast applications: video conferencing, live streaming
    • Service discovery: device discovery services
  4. Applications with a strong real-time requirement:

    • Online games: real-time interaction
    • Streaming media: audio and video transmission
    • Network monitoring: device status monitoring
  5. Simple, efficient applications:

    • Simple protocols: custom protocols
    • Lightweight services: simple queries
    • Ad hoc communication: one-off data transfers

Glossary

TermAbbreviationExplanation
User Datagram ProtocolUDPConnectionless 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 SystemDNSA typical application that uses UDP
Dynamic Host Configuration ProtocolDHCPUses UDP
Simple Network Management ProtocolSNMPUses UDP
Network Time ProtocolNTPUses UDP
Voice over IPVoIPA real-time application that suits UDP

Found an issue with this content?

Tell us what could be improved.