← All technical notes

Networks / Field notes

Understanding TCP and UDP

Published

Transport protocols define how applications exchange data. Choosing between them starts with understanding delivery guarantees, rather than assuming one is universally faster.

Two different contracts

TCP provides an ordered byte stream. It establishes connection state, acknowledges received data, retransmits missing segments and regulates sending according to congestion and receiver capacity. Applications still need their own message boundaries: one write is not necessarily one read.

UDP delivers individual datagrams without built-in retransmission, ordering or connection establishment. Applications can implement these mechanisms themselves. QUIC, for example, uses UDP as a substrate but adds reliable streams, congestion control and encrypted transport.

SYN →
← SYN-ACK
ACK →
Application data
Conceptual TCP handshake: connection establishment is separate from the exchange of application data.

Choose according to the application

PropertyTCPUDP
DeliveryOrdered byte streamBest-effort datagrams
Loss recoveryBuilt into transportApplication responsibility
Typical useSSH, HTTP/1.1, HTTP/2Real-time media, DNS queries, QUIC

Diagnose by layer

Start with the listener, then examine whether connections establish and whether application responses arrive. The commands below use a documentation address; substitute a server you administer. The packet capture is bounded and does not print payload contents.

ss -lntup
curl -v --connect-timeout 5 --max-time 10 https://example.com/
sudo tcpdump -ni any -c 30 "host 192.0.2.10 and tcp port 443"

A completed handshake tells you that connection-establishment traffic traversed the path. It does not prove TLS or HTTP succeeds. A missing response could result from routing, packet loss, client behavior or a middlebox; capture at both endpoints before attributing the failure.

Measure the operation the user actually needs: a successful application request, not merely an open port.

Further reading