Transport Layer: TCP and UDP

TCPUDP
Connection-orientedConnectionless
Reliable: ACKs, retransmission, in-order deliveryUnreliable, no ordering
Flow control (sliding window) and congestion controlNone
20–60 byte header8 byte header
HTTP, FTP, SMTP, SSHDNS, DHCP, VoIP, online games, streaming

TCP Three-Way Handshake

ClientServerSYN seq = xSYN + ACK seq = y, ack = x+1ACK ack = y+1connection ESTABLISHED
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

PortServicePortService
20/21FTP53DNS
22SSH80HTTP
23Telnet443HTTPS
25SMTP110 / 143POP3 / IMAP

A Simple TCP Client (Python)

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