CN/Lesson 6 of 8/8 min read
Application Layer Protocols
Client-server and P2P models, DNS resolution and records, HTTP methods, status codes, headers, cookies, HTTP/1.1 vs HTTP/2 vs HTTP/3, HTTPS, email protocols, FTP, SSH, WebSockets and REST basics.
On this page
Application Layer
The application layer contains the protocols that applications use directly: web, email, file transfer, name resolution, remote login.
Architectures
Client-Server Model
An always-on server with a well-known address serves many clients. Clients do not talk to each other directly. Examples: web, email, databases. Scale by adding servers behind a load balancer.
Peer-to-Peer
Peers act as both clients and servers, sharing resources directly (BitTorrent, blockchain networks, WebRTC calls). Self-scaling (each new peer adds capacity) but harder to manage and secure. Hybrid systems use a central server only for discovery.
DNS
The Domain Name System translates human-readable names (example.com) into IP addresses. It is a hierarchical, distributed database, mostly over UDP port 53 (TCP 53 for large responses and zone transfers).
Hierarchy
. (root)
/ | \
.com .org .in (TLD servers)
|
example.com (authoritative servers)
|
www.example.com- Root servers: 13 named root server identities (a to m), each served by many anycast instances worldwide.
- TLD servers:
.com,.org, country codes. - Authoritative name servers: hold the actual records for a domain.
Recursive Resolver
Resolution of www.example.com:
- Browser cache, OS cache and the
hostsfile are checked. - The stub resolver asks the configured recursive resolver (ISP,
8.8.8.8,1.1.1.1). - The resolver asks a root server, which refers it to the
.comTLD servers. - It asks a TLD server, which refers it to
example.com's authoritative servers. - It asks the authoritative server, which returns the A record.
- The resolver caches the answer for its TTL and returns it.
The client-to-resolver query is recursive ("give me the final answer"); resolver-to-servers queries are iterative ("give me the answer or a referral").
DNS Records
| Record | Purpose |
|---|---|
| A | Name to IPv4 address |
| AAAA | Name to IPv6 address |
| CNAME | Alias to another name (cannot be at the zone apex) |
| MX | Mail server for the domain, with priority |
| NS | Authoritative name servers for the zone |
| TXT | Arbitrary text: SPF, DKIM, DMARC, domain verification |
| SOA | Zone metadata: primary server, serial, timers |
| PTR | Reverse lookup: IP to name |
| SRV | Service location (host and port) |
| CAA | Which CAs may issue certificates for the domain |
Security: DNS is unauthenticated by default, enabling cache poisoning and spoofing. DNSSEC signs records; DoH/DoT (DNS over HTTPS/TLS) encrypt queries for privacy. See DNS attacks.
HTTP
HTTP (HyperText Transfer Protocol) is the request-response protocol of the web. It is stateless: each request is independent; state is added with cookies or tokens.
Request:
GET /products?id=42 HTTP/1.1
Host: shop.example.com
User-Agent: Mozilla/5.0
Accept: text/html
Cookie: session=abc123Response:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 5120
Cache-Control: max-age=3600
Set-Cookie: theme=dark; Secure; HttpOnly; SameSite=Lax
<html>...HTTP Methods
| Method | Purpose | Safe | Idempotent |
|---|---|---|---|
| GET | Read a resource | Yes | Yes |
| HEAD | Like GET, headers only | Yes | Yes |
| POST | Create, or submit data for processing | No | No |
| PUT | Replace a resource entirely | No | Yes |
| PATCH | Partially update | No | Not necessarily |
| DELETE | Remove | No | Yes |
| OPTIONS | Ask which methods are allowed (CORS preflight) | Yes | Yes |
Safe: does not change server state. Idempotent: repeating it has the same effect as doing it once (important for retries; see idempotency).
HTTP Status Codes
| Class | Meaning | Common codes |
|---|---|---|
| 1xx | Informational | 101 Switching Protocols (WebSocket upgrade) |
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 302 Found, 304 Not Modified, 307/308 keep method |
| 4xx | Client error | 400 Bad Request, 401 Unauthorized (not authenticated), 403 Forbidden (not allowed), 404 Not Found, 409 Conflict, 429 Too Many Requests |
| 5xx | Server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout |
Important headers
Host,User-Agent,Accept,Content-Type,Content-Length- Caching:
Cache-Control,ETag,If-None-Match,Last-Modified,Expires - Auth:
Authorization: Bearer <token> - Security:
Strict-Transport-Security,Content-Security-Policy,X-Content-Type-Options(see web security) - CORS:
Origin,Access-Control-Allow-Origin
Cookie
A cookie is a small piece of data the server sets with Set-Cookie, which the browser sends back on later requests to the same site. Used for sessions, preferences, tracking.
Attributes: Expires/Max-Age, Domain, Path, Secure (HTTPS only), HttpOnly (not readable by JavaScript, limits XSS theft), SameSite (Strict, Lax, None; limits CSRF).
Keep-Alive
HTTP/1.0 opened a new TCP connection per request. HTTP/1.1 made persistent connections (keep-alive) the default, reusing one connection for many requests. Pipelining existed but suffered from head-of-line blocking and was rarely enabled.
HTTP/2
- Binary framing instead of text.
- Multiplexing: many concurrent request/response streams over one TCP connection.
- Header compression (HPACK).
- Stream prioritization; server push (now deprecated in browsers).
- Still suffers TCP-level head-of-line blocking: one lost packet stalls all streams.
HTTP/3
HTTP over QUIC (UDP). Removes TCP head-of-line blocking, faster handshakes (1-RTT, 0-RTT), connection migration, header compression with QPACK. See QUIC.
| HTTP/1.1 | HTTP/2 | HTTP/3 | |
|---|---|---|---|
| Transport | TCP | TCP | QUIC over UDP |
| Format | Text | Binary | Binary |
| Multiplexing | No (one request at a time per connection) | Yes | Yes |
| Head-of-line blocking | HTTP and TCP level | TCP level | None at transport |
HTTPS
HTTPS = HTTP over TLS on port 443. It provides confidentiality (encryption), integrity (tamper detection) and authentication (the server proves its identity with a certificate signed by a trusted CA). The TLS handshake and certificates are covered in cryptography.
Email protocols
SMTP
Simple Mail Transfer Protocol sends mail: client to server and server to server. Port 25 (server relay), 587 (submission with STARTTLS), 465 (implicit TLS). Push protocol.
POP3
Post Office Protocol v3 (port 110, 995 with TLS) downloads mail to the client and usually deletes it from the server. Simple, single device.
IMAP
Internet Message Access Protocol (port 143, 993 with TLS) keeps mail on the server and syncs folders and read status across devices. Standard today.
Email authentication: SPF (which servers may send for a domain), DKIM (cryptographic signature on messages), DMARC (policy for failures). All published as DNS TXT records; they fight spoofing and phishing.
FTP
File Transfer Protocol uses two TCP connections: control on port 21 and data on port 20 (active mode) or a negotiated port (passive mode, NAT friendly). Sends credentials in plaintext; use SFTP (over SSH) or FTPS (over TLS) instead.
SSH
Secure Shell (TCP port 22) gives encrypted remote login, command execution, file transfer (SCP, SFTP) and port forwarding (tunneling). Supports password and public key authentication (preferred). Replaced Telnet (port 23, plaintext).
WebSocket
A WebSocket is a persistent, full-duplex connection between browser and server over a single TCP connection.
- Starts as an HTTP request with
Upgrade: websocket; the server replies101 Switching Protocols. - Afterwards either side can send messages at any time (no request-response).
ws://andwss://(over TLS).- Used for chat, live dashboards, multiplayer games, collaborative editing.
Alternatives: long polling (client holds a request open until data arrives) and Server-Sent Events (one-way server to client stream over HTTP).
Other protocols worth knowing
| Protocol | Port | Purpose |
|---|---|---|
| Telnet | 23 | Plaintext remote login (obsolete) |
| SNMP | 161/162 UDP | Network device monitoring |
| NTP | 123 UDP | Clock synchronization |
| LDAP | 389 (636 TLS) | Directory services |
| RDP | 3389 | Windows remote desktop |
| SIP | 5060 | VoIP call setup |
Quick revision
- DNS: recursive resolver walks root, TLD, authoritative; answers cached by TTL.
- A, AAAA, CNAME, MX, NS, TXT are the must-know records.
- GET, PUT, DELETE are idempotent; POST is not.
- 401 = not authenticated, 403 = authenticated but not allowed.
- HTTP/2 multiplexes over TCP; HTTP/3 uses QUIC and removes transport head-of-line blocking.
- SMTP sends; POP3 downloads; IMAP syncs.