Transport Layer: TCP and UDP
End-to-End Delivery
Transport layer role
The transport layer provides process-to-process communication using port numbers. It multiplexes traffic so many applications can share a single IP address.
TCP vs UDP
TCP emphasizes reliability, order, and congestion control. UDP emphasizes low overhead and low latency, leaving reliability to the application if needed.
TCP mechanics
TCP uses sequence numbers, acknowledgments, retransmissions, and flow control to provide a reliable byte stream. Connection setup is typically described as a -way handshake.
What is the purpose of a TCP sequence number?
Sequence numbers allow the receiver to reconstruct order and detect missing data.
Correct answer: To identify the order of bytes in the stream
Why might an application choose UDP instead of TCP?
UDP avoids connection setup and some transport overhead.
Correct answer: It needs lower latency or can tolerate some loss, such as in streaming or real-time apps
TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Connection setup | Yes | No |
| Reliability | Yes | No built-in |
| Ordering | Yes | No guarantee |
| Overhead | Higher | Lower |
Which TCP mechanism helps prevent a fast sender from overwhelming a slow receiver?
Flow control uses the receiver's advertised window to regulate sending.
Correct answer: Flow control
When to think TCP first
-
1
Step 1: Ask whether the application needs reliable delivery.
-
2
Step 2: Determine whether message ordering matters.
-
3
Step 3: Consider whether connection setup overhead is acceptable.
-
4
Step 4: Select UDP only if the application can handle loss or latency-sensitive behavior.
What does the -way handshake establish?
It confirms both sides can send and receive and agree on initial sequence numbers.
Correct answer: A synchronized connection state between client and server