Transport protocols decide how application data moves between endpoints. Sockets expose that machinery to programs. TCP presents a reliable, ordered byte stream while a connection remains viable. UDP sends independent datagrams and leaves loss recovery, ordering, and pacing to the application.

That distinction matters most when a network degrades. TCP hides isolated loss through retransmission, which can delay later bytes. UDP does not delay later datagrams to recover an earlier one; an application protocol can detect a missing or stale sample only when it adds sequence or timing metadata, then decide whether recovery is still worthwhile.

TCP vs UDP

Sockets describes the operating-system API used to program either transport. It is an endpoint abstraction, not a third transport.

PropertyTCPUDP
ConnectionConnection-oriented. An ordinary connection starts with a three-way handshakeConnectionless. No transport handshake
DeliveryRetransmits loss and reports connection failure when recovery cannot continueBest-effort. Datagrams may be lost, duplicated, or reordered
OrderingIn-order via sequence numbersNone. Datagrams can arrive out of order
Flow / congestion controlBuilt inNone in UDP itself. Sustained senders must pace traffic above it
FramingByte stream. The application defines message boundariesDatagrams. Each received datagram keeps its boundary
OverheadAt least a 20-byte TCP header plus connection stateAn 8-byte UDP header with little transport state
LatencyConnection setup and in-order recovery can delay dataNo transport setup or retransmission delay, though the application may add both
Fan-outPoint-to-point onlyUnicast, plus broadcast and multicast
Reach for it whenOne reliable ordered stream fits the workload: HTTP, databases, file transferThe application needs datagrams, multicast, independent recovery, or a different transport built above UDP

TCP is the usual starting point because many applications want one ordered stream and do not benefit from owning transport recovery. UDP fits real-time samples that expire quickly, small retryable exchanges such as DNS, and multicast delivery. QUIC also uses UDP, but supplies its own security, congestion control, and reliable streams above it.

References

3 items under this folder.