Skip to content
Chethan Yadav_
Computer Networks

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:

  1. Browser cache, OS cache and the hosts file are checked.
  2. The stub resolver asks the configured recursive resolver (ISP, 8.8.8.8, 1.1.1.1).
  3. The resolver asks a root server, which refers it to the .com TLD servers.
  4. It asks a TLD server, which refers it to example.com's authoritative servers.
  5. It asks the authoritative server, which returns the A record.
  6. 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

RecordPurpose
AName to IPv4 address
AAAAName to IPv6 address
CNAMEAlias to another name (cannot be at the zone apex)
MXMail server for the domain, with priority
NSAuthoritative name servers for the zone
TXTArbitrary text: SPF, DKIM, DMARC, domain verification
SOAZone metadata: primary server, serial, timers
PTRReverse lookup: IP to name
SRVService location (host and port)
CAAWhich 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=abc123

Response:

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

MethodPurposeSafeIdempotent
GETRead a resourceYesYes
HEADLike GET, headers onlyYesYes
POSTCreate, or submit data for processingNoNo
PUTReplace a resource entirelyNoYes
PATCHPartially updateNoNot necessarily
DELETERemoveNoYes
OPTIONSAsk which methods are allowed (CORS preflight)YesYes

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

ClassMeaningCommon codes
1xxInformational101 Switching Protocols (WebSocket upgrade)
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved Permanently, 302 Found, 304 Not Modified, 307/308 keep method
4xxClient error400 Bad Request, 401 Unauthorized (not authenticated), 403 Forbidden (not allowed), 404 Not Found, 409 Conflict, 429 Too Many Requests
5xxServer error500 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

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.1HTTP/2HTTP/3
TransportTCPTCPQUIC over UDP
FormatTextBinaryBinary
MultiplexingNo (one request at a time per connection)YesYes
Head-of-line blockingHTTP and TCP levelTCP levelNone 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 replies 101 Switching Protocols.
  • Afterwards either side can send messages at any time (no request-response).
  • ws:// and wss:// (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

ProtocolPortPurpose
Telnet23Plaintext remote login (obsolete)
SNMP161/162 UDPNetwork device monitoring
NTP123 UDPClock synchronization
LDAP389 (636 TLS)Directory services
RDP3389Windows remote desktop
SIP5060VoIP 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.