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"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:
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"The same exchange over UDP leaves nothing at all:
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"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"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"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"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:
cap "-i eth0 -n -c 2 udp port 53" "nslookup example.com 1.1.1.1"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 |