Skip to content
Sign inGet all access
Chapter 7·8 minFree

UDP

One datagram, no handshake — and who that suits.

Same IP header, different payload. Everything TCP adds is gone.

One datagram

Six bytes, one packet, no handshake:

cap "-i lo -n -c 1 udp port 9500" "echo hello | nc -u -w 1 127.0.0.1 9500"
OutputIP 127.0.0.1.CLIENT > 127.0.0.1.9500: UDP, length 6

Over TCP those six bytes need three packets first — chapter 3.

UDP, length 6 is the whole line — no flags, no sequence number, no acknowledgement, because none exist here.

No connection

A finished TCP connection leaves TIME_WAIT behind — chapter 5:

terminal
echo hi | nc -w 1 127.0.0.1 9000
test $(ss -tan state time-wait 'dport = :9000' | wc -l) -gt 1 \
  && echo "tcp: yes" || echo "tcp: no"
Outputtcp: yes

The same exchange over UDP leaves nothing at all:

terminal
echo hi | nc -u -w 1 127.0.0.1 9500
test $(ss -uan 'dport = :9500' | tail -n +2 | wc -l) -gt 0 \
  && echo "udp: yes" || echo "udp: no"
Outputudp: no

One write is one datagram, whatever its size:

cap "-i lo -n -c 1 udp port 9500" "printf 'x' | nc -u -w 1 127.0.0.1 9500"
OutputIP 127.0.0.1.CLIENT > 127.0.0.1.9500: UDP, length 1
terminal
head -c 1000 /dev/zero | tr '\0' 'y' > /tmp/k.txt
cap "-i lo -n -c 1 udp port 9500" "nc -u -w 1 127.0.0.1 9500 < /tmp/k.txt"
OutputIP 127.0.0.1.CLIENT > 127.0.0.1.9500: UDP, length 1000

What UDP does not do

TCP gives you UDP
Ordered delivery packets arrive in any order
Retransmission lost is lost
Acknowledgement you are never told
Flow control you can flood the receiver
A connection no state either end

What survives is a port number and a checksum.

Nothing checks anyone is there. A send to a port with no listener leaves anyway:

cap "-i lo -n -c 1 udp port 9599" "echo hi | nc -u -w 1 127.0.0.1 9599"
OutputIP 127.0.0.1.CLIENT > 127.0.0.1.9599: UDP, length 3

What that buys

No handshake, so the first packet carries data. No ordering, so one lost packet does not delay the rest.

That second point is head-of-line blocking, from the HTTP course. HTTP/3 moved to UDP to escape it.

DNS over UDP

A query and a response, two packets, no connection:

terminal
cap "-i eth0 -n -c 2 udp port 53" "nslookup example.com 1.1.1.1"
OutputIP 172.17.0.4.CLIENT > 1.1.1.1.53: 39809+ A? example.com. (29)IP 1.1.1.1.53 > 172.17.0.4.CLIENT: 39809 2/0/0 A 104.20.23.154, A 172.66.147.243 (61)

39809 is the query ID — how the client matches response to question, the job TCP’s sequence numbers would do.

Your capture will differ — the ID is random per query and the addresses change.

When it falls back

A response too large for one datagram sets a truncated flag and the client retries over TCP. Zone transfers use TCP throughout.

That is the shape of UDP in practice: a single small exchange, with a TCP path for when it does not fit.

Choosing

Use Because
DNS one question, one answer, retry is cheap
Video and voice a late packet is worse than a lost one
Games the next update replaces the lost one
QUIC and HTTP/3 reliability rebuilt per stream, above UDP