Back to Course Home
Principles HTTP Cookies Caching HTTP/2 & QUIC Email DNS Video & CDNs Socket Programming Homework

Chapter 2: Application Layer

Kurose & Ross, Computer Networking: A Top-Down Approach, 9th edition (2025) – Full lecture coverage

1. Principles of Network Applications

Network apps run on end systems (hosts) – not on core network devices. They communicate using the transport layer's services.

🏢 Client-Server Architecture

  • Server: always-on, permanent IP address, often in data centers.
  • Clients: communicate with server, may be intermittently connected, may have dynamic IP addresses.
  • Examples: Web (HTTP), email (SMTP/IMAP), FTP.

🌍 Peer-to-Peer (P2P) Architecture

  • No always-on server; arbitrary end systems (peers) communicate directly.
  • Self-scalability: new peers bring new capacity and demand.
  • Peers are intermittently connected and change IP addresses.
  • Examples: BitTorrent, Skype (legacy), file sharing.

🔌 Processes, Sockets, and Addressing

A process is a program running within a host. Processes communicate via sockets (API to the network). To identify a socket, we need both the IP address (host) and a port number (e.g., HTTP:80, SMTP:25).

Application-layer protocol defines: message types (request/response), syntax (fields and delimiters), semantics (meaning of fields), and rules for when/how processes send messages.

📡 What transport service does an app need?

🚚 Internet transport protocols

2. Web and HTTP

HTTP (HyperText Transfer Protocol) – Web's application-layer protocol. Uses TCP port 80 (default).

📄 HTTP request message (ASCII)

GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml
Accept-Language: en-us
(blank line)
    

📬 HTTP response message

HTTP/1.1 200 OK
Date: Mon, 10 Mar 2025 12:00:00 GMT
Server: Apache/2.4
Content-Type: text/html
Content-Length: 1024

(html data...)
    

Status codes: 200 OK, 301 Moved Permanently, 400 Bad Request, 404 Not Found, 505 HTTP Version Not Supported.

🍪 Cookies – maintaining user/server state

HTTP is stateless; cookies add state via:

  1. Cookie header in HTTP response (set by server)
  2. Cookie header in next HTTP request (sent by browser)
  3. Cookie file stored on user's host
  4. Back-end database at website
Privacy note: Third-party cookies can track users across sites. GDPR gives users explicit control over cookie acceptance.

💾 Web Caching (Proxy Servers)

Web cache (proxy) stores copies of objects, reducing response time and access link traffic. Browser sends requests to cache; if object is fresh, cache returns it; otherwise cache fetches from origin server.

Conditional GET: client asks "If-modified-since", server replies "304 Not Modified" if cached copy is up-to-date → saves bandwidth.

⚡ HTTP/2 and QUIC

3. E‑mail: SMTP and IMAP

Three major components: user agents (mail readers), mail servers, and SMTP (Simple Mail Transfer Protocol).

Sample SMTP interaction

S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr
C: MAIL FROM: <alice@crepes.fr>
S: 250 Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 closing connection
    

4. Domain Name System (DNS)

DNS translates hostnames (e.g., www.example.com) to IP addresses. It is a distributed hierarchical database implemented by many name servers.

DNS resolution: iterative vs. recursive

Iterated query: contacted server replies with name of next server to ask. Recursive query: puts burden on name server (rare in practice).

DNS records (Resource Records – RR)

DNS security: Cache poisoning and DDoS attacks are threats; DNSSEC provides authentication and integrity.

5. Video Streaming & Content Distribution Networks (CDNs)

Streaming video dominates Internet traffic. Challenge: deliver high-quality video to millions of heterogeneous users.

DASH (Dynamic Adaptive Streaming over HTTP)

Content Distribution Networks (CDNs)

6. Socket Programming (UDP & TCP)

Socket = door between application process and transport layer. Two main types: UDP socket (unreliable datagram) and TCP socket (reliable byte stream).

UDP socket programming (Python)

Client attaches destination IP and port to each packet; no connection setup.

# UDPClient.py
from socket import *
serverName = 'hostname'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = input('Input lowercase sentence:')
clientSocket.sendto(message.encode(), (serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print(modifiedMessage.decode())
clientSocket.close()
    
# UDPServer.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print('The server is ready to receive')
while True:
    message, clientAddress = serverSocket.recvfrom(2048)
    modifiedMessage = message.decode().upper()
    serverSocket.sendto(modifiedMessage.encode(), clientAddress)
    

TCP socket programming (Python)

Connection-oriented; server must first create a welcoming socket, then accept connections.

# TCPClient.py
from socket import *
serverName = 'servername'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
sentence = input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print('From Server:', modifiedSentence.decode())
clientSocket.close()
    
# TCPServer.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print('The server is ready to receive')
while True:
    connectionSocket, addr = serverSocket.accept()
    sentence = connectionSocket.recv(1024).decode()
    capitalizedSentence = sentence.upper()
    connectionSocket.send(capitalizedSentence.encode())
    connectionSocket.close()
    
Timeouts: Use socket.settimeout(seconds) and try-except to handle unresponsive servers.

Homework Assignment (Theoretical, Graded)

Instructions: Answer all questions in a separate document (PDF or Word). Submit via the learning platform. This assignment counts towards your final grade (5%).

Part I: Short Essays (40 points)

  1. Compare client-server and P2P architectures. Give two advantages and two disadvantages of each.
  2. Explain the difference between non-persistent HTTP and persistent HTTP. Calculate the total response time for a web page with 10 small images using non-persistent HTTP, given RTT = 100 ms and negligible transmission time.
  3. What is a cookie? How does it enable stateful behavior in HTTP? Discuss privacy concerns related to third-party cookies.
  4. Describe the role of DNS in the Internet. How does a local DNS server help reduce resolution time?
  5. What is DASH? Why is client-side adaptation critical for streaming video over the Internet?

Part II: True/False + Correction (30 points)

  1. SMTP is a pull protocol – the receiver’s mail server fetches messages from the sender’s server.
  2. UDP provides reliable, in-order delivery of data.
  3. In HTTP/1.1, multiple objects can be sent over a single TCP connection.
  4. The DNS root servers are centralized and handle all DNS queries directly.
  5. Conditional GET allows a web cache to avoid downloading an object that hasn’t changed.

For each false statement, write the correct version.

Part III: Calculations and Protocol Analysis (30 points)

  1. Assume RTT = 50 ms and an HTML file of size 10 KB plus 5 images of 20 KB each. Using non-persistent HTTP (one object per connection), compute total delay (ignore transmission time). Compare to persistent HTTP (one connection, sequential requests).
  2. Given a DNS hierarchy: Client queries local DNS, then root, then TLD (.com), then authoritative. Assume RTT between each pair is 10 ms. How long does iterative resolution take? Recursive resolution?
  3. Write a Python UDP client that sends a message "HELLO" to server at IP 127.0.0.1 port 9999, waits for response, and prints it. Include error handling for timeout (2 seconds).

Grading criteria: correctness, completeness, proper use of terminology, and clarity of explanation.

Deadline: Two weeks from the lecture date.

Chapter 2 Summary

Self-review questions (exam preparation):
• How does a web cache reduce response time?
• What is the difference between a forward proxy and a reverse proxy?
• How does DNS caching improve performance and what problems can it cause?
• Why is QUIC built on UDP instead of TCP?
• What happens when you type a URL into a browser? (steps: DNS, TCP, HTTP, rendering)