Principles of Network Applications

Network Application Architectures:

  • Client-Server: a dedicated server (always-on, fixed IP) serves requests from clients. Clients do not communicate directly with each other.
  • Peer-to-Peer (P2P): peers communicate directly, without always-on servers. Self-scalability.

Processes Communicating:

  • A process sends/receives messages via a socket (API between application and transport layer)
  • The port number identifies the receiving process on a host
  • The destination is uniquely identified by: (IP address, port number)

Transport Services Available:

ServiceTCPUDP
Reliable data transferYesNo
ThroughputNo guaranteeNo guarantee
TimingNo guaranteeNo guarantee
Security (SSL)Yes (via TLS)No
Connection-orientedYesNo

Transport Services Provided by the Internet:

  • TCP: connection-oriented, reliable, includes congestion control and flow control
  • UDP: connectionless, unreliable, no frills
  • SSL (Secure Sockets Layer): enhanced TCP with encryption, integrity, and authentication

Application-Layer Protocols define:

  • Types of messages exchanged (request, response)
  • Message syntax (format, fields)
  • Message semantics (meaning of fields)
  • Rules for when/how processes send/respond

The Web and HTTP

HTTP (HyperText Transfer Protocol):

  • Client-server protocol (Web browser ↔ Web server)
  • Uses TCP (port 80 by default)
  • Stateless — server maintains no information about past client requests

Non-Persistent vs. Persistent Connections:

  • Non-persistent (HTTP/1.0): one TCP connection per request/response pair. RTT × 2 + file transmission time per object.
  • Persistent (HTTP/1.1 default): multiple objects can be sent over a single TCP connection. Reduces overhead.

HTTP with non-persistent connections: Time to receive one file = 2×RTT + (file size / transmission rate)

HTTP Message Format:

Request message:

  • Request line (method, URL, version): e.g., GET /index.html HTTP/1.1
  • Header lines: Host:, Connection:, User-Agent:, Accept-Language:
  • Blank line
  • Entity body (for POST)

Response message:

  • Status line (version, status code, phrase): e.g., HTTP/1.1 200 OK
  • Header lines: Date:, Server:, Last-Modified:, Content-Length:, Content-Type:
  • Blank line
  • Entity body (requested data)

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

Cookies — Allow websites to track users across sessions. Four components: cookie header in HTTP response, cookie header in HTTP request, cookie file on client, back-end database on server.

Web Caching (Proxy Server):

  • A Web cache (proxy server) stores copies of recently requested objects
  • Reduces response time for client requests
  • Reduces traffic on an institution’s access link
  • Conditional GET (If-Modified-Since header) ensures cache is fresh

Electronic Mail

Three Major Components:

  1. User agents (Outlook, Thunderbird, mobile mail apps)
  2. Mail servers (mailbox + message queue)
  3. SMTP (Simple Mail Transfer Protocol)

SMTP:

  • Uses TCP (port 25)
  • Transfers messages from sender’s mail server to receiver’s mail server
  • Direct transfer (no intermediate mail servers)
  • Uses persistent connections
  • Requires 7-bit ASCII encoding

Mail Access Protocols:

  • POP3 (Post Office Protocol v3): download-and-delete or download-and-keep
  • IMAP (Internet Mail Access Protocol): server stores messages in folders, allows remote folder management
  • HTTP: Web-based email (Gmail, Outlook.com)

Message Format:

  • Header: From:, To:, Subject:
  • Body (ASCII text)
  • MIME (Multimedia Internet Mail Extension) enables non-ASCII content

DNS — The Internet’s Directory Service

Services Provided by DNS:

  • Hostname to IP address translation
  • Host aliasing (canonical vs. alias names)
  • Mail server aliasing
  • Load distribution (round-robin among replicated servers)

DNS is a distributed, hierarchical database, implemented in a hierarchy of DNS servers. It uses UDP (port 53).

DNS Hierarchy:

  1. Root DNS servers (13 logical root servers, ~200 physical servers worldwide)
  2. Top-Level Domain (TLD) servers (.com, .org, .net, .edu, .gov, country TLDs)
  3. Authoritative DNS servers (provide authoritative hostname-to-IP mappings for organizations)

Local DNS Server (LDNS) — acts as a proxy, forwarding queries into the hierarchy.

Query Types:

  • Iterative query: the contacted server replies with the next server to contact
  • Recursive query: the contacted server takes responsibility for finding the answer

DNS Caching — DNS servers cache mappings to improve performance. Entries are discarded after a time-to-live (TTL).

DNS Records (Resource Records): stored in DNS servers with format: (Name, Value, Type, TTL)

TypeNameValue
AhostnameIP address
NSdomainhostname of authoritative DNS server
CNAMEalias namecanonical name
MXnamemail server canonical name

DNS Messages: both query and reply use the same format with 12-byte header + question section + answer section + authority section + additional section.

DNS Registration: an organization registers its domain name with a registrar, providing names/IPs of its primary and secondary authoritative DNS servers.

Peer-to-Peer Applications

P2P File Distribution (BitTorrent):

  • Tracker: tracks which peers are participating in the torrent
  • Torrent: group of peers exchanging chunks of a file
  • Chunks: a file is divided into 256KB chunks
  • Tit-for-tat: a peer gives chunks to neighbors that are currently providing chunks at the highest rate

P2P self-scalability: the total service capacity (upload bandwidth) grows with the number of peers, unlike the client-server model.

Video Streaming and Content Distribution Networks

Internet Video: video is compressed; multiple versions at different quality/bitrates can be created.

DASH (Dynamic Adaptive Streaming over HTTP):

  • Video is encoded into multiple versions at different rates
  • Video is divided into chunks (a few seconds each)
  • Client requests chunks dynamically, adapting to available bandwidth
  • Manifest file provides URL and bitrate for each version

Content Distribution Networks (CDN):

  • Private CDN (e.g., Google’s CDN for YouTube)
  • Third-party CDN (e.g., Akamai, Limelight, Level-3)

CDN strategies:

  • Enter deep: many server clusters close to users (Akamai)
  • Bring home: fewer large clusters at key locations (Google, Netflix via Amazon Cloud)

CDN selects the server cluster based on: DNS-based redirection, client LDNS IP address, real-time cluster load measurements.

Case Studies:

  • Netflix: uses Amazon Cloud + own Open Connect CDN appliances in ISPs
  • YouTube: cache-friendly, Google’s private CDN in data centers
  • Kankan: P2P-based streaming

Socket Programming

Socket — the API between an application process and the transport layer. Two types:

UDP Socket:

  • Connectionless: no handshake before sending
  • Must attach destination address to each packet (datagram)
  • UDPClient.sendto(message_bytes, (server_hostname, server_port))
1
2
3
4
5
6
7
# UDP Client
from socket import *
serverName = 'hostname'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
clientSocket.sendto(message.encode(), (serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)

TCP Socket:

  • Connection-oriented: client establishes TCP connection with server via a three-way handshake
  • Once connection established, sends bytes as a stream (no need to attach address)
  • Server creates a welcome socket (port) and a connection socket for each client
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# TCP Server
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)  # listen for up to 1 client
while True:
    connectionSocket, addr = serverSocket.accept()
    sentence = connectionSocket.recv(1024).decode()
    connectionSocket.send(capitalizedSentence.encode())
    connectionSocket.close()

Key Formula

ConceptFormulaVariable Meaning
HTTP non-persistent (1 object)Time = 2×RTT + L/RRTT = round-trip time

References

  • Computer Networking: A Top-Down Approach, 7th Edition — James F. Kurose and Keith W. Ross, Pearson, 2017
  • RFC 2616 — HTTP/1.1
  • RFC 5321 — Simple Mail Transfer Protocol
  • RFC 1034/1035 — Domain Names