ID
2
ย
Chapter 2: Application Layer
๐น 1. Key Concepts: Application Layer Overview
โ What Is the Application Layer?
- Main Role: Enables network applications (e.g., web browsers, email, video streaming).
- Not part of network core: Runs only on end systems (hosts), not on routers/switches.
- Design Goal: Understand how apps use transport protocols to communicate.
โ Two Architectures
Client-Server | Peer-to-Peer (P2P) |
- Always-on server with permanent IP | - No always-on server |
- Clients request service | - Peers request and provide services |
- Centralized control | - Decentralized, self-scaling |
- Examples: HTTP, SMTP, FTP | - Examples: BitTorrent, Skype (older), sharing apps |
- Clients may have dynamic IPs | - Peers intermittently connected, IPs change |
- Scalability limited by server capacity | - Scalability improves as peers join |
๐ก Key Insight: P2P = "Everyone is both client AND server." ๐ก Tradeoff: P2P scales well, but hard to manage; client-server is simpler but bottlenecked at server.
๐น 2. Processes & Sockets
โ Process Communication
- Same host: Use inter-process communication (IPC).
- Different hosts: Communicate via messages over network.
- Client process: Initiates communication.
- Server process: Waits to be contacted.
โ Sockets: The โDoorโ to the Network
- Socket = interface between app and transport layer (TCP/UDP).
- Analogy: Like a mailbox or door โ app pushes data out, transport delivers it.
- Two sockets per connection: One on client, one on server.
โ Process Addressing: IP + Port
- IP address: Identifies host.
- Port number: Identifies process on that host.
- Example:
gaia.cs.umass.edu:80โ Web server at IP128.119.245.12, port 80.
- Well-known ports:
- HTTP โ 80
- HTTPS โ 443
- SMTP โ 25
- DNS โ 53
- FTP โ 21
- POP3 โ 110
- IMAP โ 143
โ Exam Tip: IP address alone is NOT enough โ you need IP + port to identify a process.
๐น 3. Application-Layer Protocols: Requirements
โ What Defines a Protocol?
An application-layer protocol specifies:
- Message types: Request, response, etc.
- Syntax: Field structure, delimiters (e.g.,
CRLF).
- Semantics: Meaning of fields (e.g.,
GET= request object).
- Rules: When and how to send/respond.
โ Transport Service Requirements by App
Application | Data Loss Tolerance | Throughput | Timing | Security |
File Transfer / Email / Web | No loss | Elastic | No | Yes |
Real-time Audio/Video | Loss-tolerant | 5Kโ5Mbps | Yes (10sโ100s ms) | Yes |
Interactive Games | Loss-tolerant | Kbps+ | Yes (10s ms) | Yes |
Text Messaging | No loss | Elastic | Sometimes | Yes |
โ Transport Protocols: TCP vs UDP
Feature | TCP | UDP |
Reliability | โ
Yes (retransmissions) | โ No |
Ordering | โ
In-order delivery | โ May arrive out of order |
Flow Control | โ
Yes | โ No |
Congestion Control | โ
Yes | โ No |
Connection Setup | โ
3-way handshake | โ None |
Overhead | Higher | Lower |
Use Cases | Web, email, FTP | Video, VoIP, DNS, streaming |
โ ๏ธ Why UDP?
- Low latency (e.g., live video)
- No connection setup (e.g., DNS queries)
- App handles reliability (e.g., RTSP, QUIC)
๐น 4. Web & HTTP (CORE TOPIC)
โ HTTP Basics
- HyperText Transfer Protocol
- Client-Server: Browser (client) โ Web server (server)
- Uses TCP: Port 80 (HTTP), 443 (HTTPS)
- Stateless: Server remembers nothing between requests.
โ HTTP Connection Types
Non-Persistent HTTP (HTTP 1.0) | Persistent HTTP (HTTP 1.1) |
- One TCP conn per object | - Single TCP conn for multiple objects |
- 2 RTTs per object | - 1 RTT total for all objects |
- High overhead: open/close TCP | - Connection kept open: Connection: keep-alive |
- Inefficient for pages with many resources | - Supports pipelining (optional) |
๐ Example: A webpage with 10 images =
- Non-persistent: 22 RTTs (2 RTT ร 11 objects)
- Persistent: 2 RTTs (1 to open + 1 for all)
โ HTTP Messages: Request & Response
โค HTTP Request Format (GET example):
- Request Line:
Method URI Version
- Headers: Key-value pairs
- Blank line ends headers
- Body: Optional (for POST/PUT)
โค HTTP Response Format:
- Status Line:
Version Code Phrase
- Headers
- Body: HTML, image, etc.
๐ HTTP Status Codes (Must Know!)
Code | Meaning |
200 OK | Success |
301 Moved Permanently | Page moved โ new URL in Location: header |
400 Bad Request | Syntax error |
404 Not Found | File doesnโt exist |
505 HTTP Version Not Supported | Server doesnโt support requested version |
โ HTTP Methods (Commands)
Method | Purpose |
GET | Retrieve object |
POST | Submit form data (body used) |
HEAD | Get headers only (no body) |
PUT | Upload file (replace existing) |
DELETE | Delete file |
๐กGETcan send data via URL (?key=value) โ but only for small data.
๐น 5. Keeping State: Cookies
โ Why Need Cookies?
- HTTP is stateless โ server canโt remember who you are.
- Solution: Cookies โ track user state across requests.
โ Cookie Process (4 Components)
- Server sends
Set-Cookie: session_id=12345in response.
- Browser saves cookie in cookie file.
- Browser includes
Cookie: session_id=12345in next request.
- Server uses cookie to identify user โ accesses backend DB.
โ Cookie Uses
- Authentication (login sessions)
- Shopping carts
- Personalization (recommendations)
- User tracking
โ Privacy & Third-Party Cookies
- First-party cookie: From site you visited (e.g., amazon.com)
- Third-party cookie: From tracker site (e.g., adX.com embedded in nytimes.com)
- Tracks you across multiple sites
- Used for targeted ads
- Disabled by default in Safari, Firefox; being phased out in Chrome
- GDPR (EU): Requires user consent โ cookies = personal data if can identify you.
๐น 6. Web Caching (Proxy Servers)
โ Purpose
- Reduce latency + reduce bandwidth on access link.
- Store copies of objects closer to user.
โ How It Works
- Client โ requests โ web cache
- Cache โ if object exists โ deliver it (cache hit)
- Cache โ if not โ fetch from origin server, cache, deliver (cache miss)
โ Cache Hit Rate = % requests served from cache
- Example: Hit rate = 0.4 โ 40% hits, 60% misses
โ Performance Improvement Example:
Configuration | Access Link Utilization | Avg. Delay |
No cache | 0.97 (high) | ~3โ5 minutes |
With cache (40% hit) | 0.58 | ~1.2 seconds |
๐ก Caching is cheaper & more effective than upgrading bandwidth!
โ Conditional GET (Efficiency!)
- Client sends:
If-Modified-Since: Tue, 01 Mar 2016 18:57:50 GMT
- Server responds with:
- 304 Not Modified โ client uses cached copy (no data transfer)
- 200 OK + data โ object updated
๐น 7. HTTP/2 & HTTP/3 / QUIC
โ HTTP/1.1 Issue: HOL Blocking
- One large object blocks smaller ones (First-Come-First-Served).
- 1 TCP connection โ packet loss stalls all.
โ HTTP/2 (2015) Fixes:
- Multiplexing: Objects split into frames, interleaved โ no HOL blocking.
- Server Push: Server sends resources it thinks client will need (e.g., CSS, JS).
- Header Compression: Reduces overhead.
- Still uses TCP.
โ HTTP/3 (2022) โ QUIC
- Over UDP, not TCP.
- Built-in encryption + authentication (TLS 1.3).
- 0-RTT or 1-RTT connection setup.
- Per-flow congestion control โ no HOL blocking between streams.
- Better for mobile & unstable networks.
- Used by Google, YouTube, Chrome.
๐ QUIC = UDP + TLS + Reliable Transport (TCP-like) in App Layer
Real World: HTTP/2 โ TCP โ QUIC
๐น 8. Email: SMTP, POP3, IMAP
โ 3 Components of Email System
- User Agent (UA): Mail client (Outlook, iPhone Mail)
- Mail Server: Stores inbox/outbox
- SMTP: Protocol to send mail
โ SMTP (Simple Mail Transfer Protocol)
- Reliable transfer via TCP (port 25)
- Three Phases:
- Handshake (HELO)
- Transfer (MAIL FROM, RCPT TO, DATA)
- Closure (QUIT)
- ASCII only โ binary data must be base64 encoded.
- Push protocol: Client pushes mail to server.
โ SMTP Interaction Example:
โ Email Message Format (RFC 2822)
- Headers (To, From, Subject)
- Blank line
- Body (ASCII text)
โ SMTP vs HTTP:
- SMTP: Push โ client sends to server
- HTTP: Pull โ client requests from server
โ Retrieving Mail: IMAP vs POP3
Protocol | Stores Mail | Syncs State | Webmail Ready? |
POP3 | Downloads โ deletes from server | โ No | โ No |
IMAP | Keeps on server | โ
Yes | โ
Yes |
โ Modern Use: IMAP (Gmail, Outlook) โ emails synced across phones/computers.
๐น 9. DNS: Domain Name System
โ Why DNS?
- Humans:
www.amazon.com
- Machines:
54.240.10.10
- DNS = Translator (name โ IP)
โ Why Distributed & Hierarchical?
- โ Centralized โ Single point of failure, traffic overload
- โ Decentralized = scalable, reliable
โ DNS Hierarchy (Top to Bottom)
โ DNS Servers Types
Server | Role |
Root | Point to TLD servers |
TLD | .com, .edu โ points to authoritative servers |
Authoritative | Owns DNS records for domain (e.g., amazon.com) |
Local (Recursive) | ISPโs DNS server โ handles query for host |
โ DNS Query Types
Type | Description |
Iterative | Server responds: โI donโt know, ask THIS serverโ โ client follows chain |
Recursive | Server must resolve it โ high load on root/TLD โ rare |
โ Most DNS queries use recursion at local server โ it does iterative on your behalf.
โ DNS Record Types (RR) โ MUST KNOW!
Type | Meaning | Example |
A | Hostname โ IP | www.example.com โ 192.0.2.1 |
CNAME | Alias โ canonical name | www.amazon.com โ amazon.com.edgesuite.net |
MX | Mail server | example.com โ mail.example.com |
NS | Nameserver for domain | example.com โ ns1.example.com |
โ DNS Caching & TTL
- DNS servers cache entries for TTL (Time To Live) seconds.
- Problems:
- Changes (e.g., IP change) take time to propagate.
- Outdated records โ misrouting.
โ DNS is best-effort โ can be inaccurate.
โ DNS Security (DNSSEC)
- Adds digital signatures โ prevents spoofing & cache poisoning.
- Authenticates DNS responses.
โ DNS Attack: DDoS
- Flooding root/TLD servers โ disrupt Internet.
- Defenses:
- Local caching of TLD IPs
- Filtering
- Replication
๐น 10. Video Streaming & CDNs
โ Challenges
- Scalability: 1B+ viewers
- Heterogeneity: Different bandwidths (mobile, wired)
- Jitter: Variable delays โ_irq=planning playout
- Loss: Video packets may drop
โ Video Coding
- Spatial coding: Compress within frame (e.g., repeated colors)
- Temporal coding: Compress between frames (e.g., only send changes)
- CBR: Constant Bitrate โ Film
- VBR: Variable Bitrate โ Internet โ adaptive streaming
โ Streaming Architecture
- Video recorded โ encoded โ divided into chunks
- Each chunk encoded at multiple bitrates
- Client requests chunks via HTTP
- Client chooses bitrate based on current bandwidth
โ DASH: Dynamic Adaptive Streaming over HTTP
- Client:
- Estimates bandwidth
- Requests highest sustainable bitrate chunk
- Can change per chunk (e.g., from 1080p โ 720p)
๐ก DASH = Adaptation + HTTP + Chunking = Standard today (Netflix, YouTube)
โ Content Distribution Networks (CDNs)
- Problem: Single server canโt handle 1M users โ overload, latency.
- Solution: Replicate content across thousands of geographically distributed servers.
โ CDN Example: Netflix
- Netflix uploads movie to CDN nodes globally.
- User requests video โ DNS returns CDN URL (CNAME)
- Client gets manifest file โ picks closest/server with good bandwidth
- Downloads chunk-by-chunk via HTTP (DASH)
๐ฅ Akamai: 240,000 servers โ 1/4 of Internet traffic
๐ก CDNs = Edge Computing โ move content as close as possible to users.
๐น 11. Socket Programming (Python)
โ Two Types of Sockets
Socket | Protocol | Use |
UDP Socket | UDP | Fast, unreliable (e.g., DNS, video) |
TCP Socket | TCP | Reliable, connection-oriented (e.g., web, email) |
โ UDP Client-Server (Unreliable)
Client:
Server:
โ ๏ธ No connection โ address must be included insendto().
โ TCP Client-Server (Reliable)
Client:
Server:
โ ๏ธ Key difference:
- TCP: Use
connect()+accept()โ connection established
- UDP: Send/receive without connection
โ Handling Timeouts (Critical for Labs!)
- Used in RDT programming assignments (Chapter 3) โ essential for timeouts!
๐จ Chapter 2: Exam Checklist (Must Know!)
Topic | Must Know? |
Client-server vs P2P | โ๏ธ |
Process = IP + Port | โ๏ธ |
Socket = handoff point to transport layer | โ๏ธ |
TCP vs UDP features & use cases | โ๏ธโ๏ธโ๏ธ |
HTTP: Stateless, Non-persistent vs Persistent | โ๏ธโ๏ธโ๏ธ |
HTTP request/response syntax, status codes | โ๏ธโ๏ธโ๏ธ |
Cookies โ 4 components, use, privacy (GDPR) | โ๏ธโ๏ธ |
Web caching: hit rate, advantage over bandwidth upgrade | โ๏ธโ๏ธ |
DNS hierarchy, record types (A, CNAME, MX, NS) | โ๏ธโ๏ธโ๏ธ |
UDP vs Recursive queries | โ๏ธ |
DNS caching & TTL | โ๏ธ |
DASH โ adaptive bitrate, chunked streaming | โ๏ธโ๏ธ |
CDNs -> Why? (scalability, latency, replication) | โ๏ธโ๏ธ |
HTTP/2 โ multiplexing, server push | โ๏ธ |
HTTP/3 โ QUIC over UDP, 0-RTT, security | โ๏ธ |
SMTP: 3 phases, ASCII, STORED on server | โ๏ธ |
IMAP vs POP3 | โ๏ธ |
TCP/UDP socket programming in Python | โ๏ธโ๏ธโ๏ธ |
Socket timeout in Python | โ๏ธโ๏ธ (Very Important!) |
๐ Final Thoughts: Key Themes of Chapter 2
- Client-Server: Simple, centralized, brittle
- P2P: Scalable, decentralized, complex
- Stateless vs Stateful: HTTP vs Cookies
- Reliability: TCP vs UDP tradeoffs
- Scalability: CDNs, Caching, DASH
- Complexity at Edge: Everything real happens in apps (DNS, codecs, security)
- Use the Interface: Sockets abstract away network complexity
๐ฌ โThe Internet is designed to run on end systemsโitโs not about infrastructure, itโs about applications.โ
๐ Practice & Labs
- Use Wireshark โ capture HTTP, DNS, SMTP traffic.
- Run the Python socket code examples.
- Try
telnet gaia.cs.umass.edu 80โ sendGET / HTTP/1.1\\r\\nHost: gaia.cs.umass.edu\\r\\n\\r\\n
- Practice traceroute + dig/nslookup for DNS.
โ You now have a complete, exam-ready understanding of the Application Layer. Dig deeper into protocols โ youโre ready for Chapter 3 (Transport Layer).
Good luck in your exams! ๐๐ป๐






