Transport Layer
TCP, UDP, ports, and reliability
01Role
L4 provides process-to-process delivery via ports. It multiplexes many applications over one IP address. The socket (IP + port) is the endpoint.
02TCP
Connection-oriented, reliable, ordered, flow- and congestion-controlled. Three-way handshake establishes state; four-way teardown closes it.
- ▸SYN → SYN-ACK → ACK
- ▸Sequence & ack numbers track bytes
- ▸Sliding window for flow control
- ▸Slow start, congestion avoidance, fast retransmit
TCP Three-Way Handshake
03TCP state machine
A connection moves through states. Understanding them explains TIME_WAIT, half-open connections, and port exhaustion.
TCP Connection State Machine
No connection.
04UDP
Connectionless, best-effort, low overhead. No handshake, no ordering, no retransmission. Used where latency matters: DNS, VoIP, gaming, QUIC/HTTP3, video streaming.
05Ports
Well-known (0–1023), registered (1024–49151), ephemeral (49152–65535). A socket = IP + port. Port 80 HTTP, 443 HTTPS, 53 DNS, 22 SSH, 25 SMTP.
06TCP vs UDP
TCP: reliability, ordering, congestion control, higher latency. UDP: speed, no guarantees, app handles reliability. HTTP/3 moved to QUIC (UDP) to get both speed and reliability.