Transport Layer: TCP and UDP
| TCP | UDP |
|---|---|
| Connection-oriented | Connectionless |
| Reliable: ACKs, retransmission, in-order delivery | Unreliable, no ordering |
| Flow control (sliding window) and congestion control | None |
| 20–60 byte header | 8 byte header |
| HTTP, FTP, SMTP, SSH | DNS, DHCP, VoIP, online games, streaming |
TCP Three-Way Handshake
TCP Congestion Control
- Slow start: cwnd doubles every RTT until it reaches ssthresh.
- Congestion avoidance: cwnd grows by 1 MSS per RTT (additive increase).
- On timeout: ssthresh = cwnd/2, cwnd = 1 (TCP Tahoe).
- On 3 duplicate ACKs: fast retransmit and fast recovery (TCP Reno).
Well-Known Ports
| Port | Service | Port | Service |
|---|---|---|---|
| 20/21 | FTP | 53 | DNS |
| 22 | SSH | 80 | HTTP |
| 23 | Telnet | 443 | HTTPS |
| 25 | SMTP | 110 / 143 | POP3 / IMAP |
A Simple TCP Client (Python)
import socket
s = socket.create_connection(("example.com", 80))
s.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
print(s.recv(64).decode())
s.close()
HTTP/1.1 200 OK
Content-Type: text/html; ch
Track your progress through the Computer Networks course