Skip to main content

Computer Networks

Application Layer

The application layer is about recognition and short timing calculations: know what DNS records do, how HTTP connection modes change the page-load time, which mail protocol does what, and the socket call sequence.

~4 hrs ~0.5–1 marks · Moderate 10 samples · 8 practice · 9 cards

GATE CSE application layer — DNS hierarchy and record types, recursive and iterative resolution, HTTP methods, status codes, persistent and non-persistent timing, cookies and caching, SMTP, POP3, IMAP, FTP, well-known ports and the socket API, with samples, flashcards and drills.

Learning outcomes

  • Explain the DNS hierarchy, record types and resolution (recursive vs iterative)
  • Use HTTP methods and status codes and compute page-load time for persistent and non-persistent modes
  • Describe the roles of SMTP, POP3, IMAP and the two FTP connections
  • Recall well-known ports and the order of socket API calls

DNS — the Domain Name System

  • DNS maps HOST NAMES to IP addresses (and back). It is a distributed, HIERARCHICAL database: ROOT servers, TOP-LEVEL DOMAIN (TLD) servers (.com, .org, .in), AUTHORITATIVE servers of each organisation, plus LOCAL (default) resolvers run by an ISP or campus.
  • DNS mostly uses UDP port 53 (queries and responses fit in a datagram); TCP port 53 is used for zone transfers and large responses.
  • RESOURCE RECORDS (name, value, type, TTL): A = name to IPv4 address; AAAA = IPv6 address; NS = authoritative name server of a domain; CNAME = canonical name (alias); MX = mail exchanger; PTR = reverse lookup (address to name); SOA = start of authority; TXT = free text.
  • RECURSIVE query: the contacted server resolves the name completely and returns the final answer. ITERATIVE query: the server returns the best referral and the client asks the next server itself. Typically the host asks its local resolver recursively and the resolver walks root -> TLD -> authoritative iteratively.
  • CACHING: every server caches records for the TTL, which removes most root and TLD traffic and speeds up repeated lookups. Cached answers can be stale until the TTL expires.
  • A DNS MESSAGE has a 16-bit identification, flags (query/response, authoritative answer, recursion desired and available) and question, answer, authority and additional sections; queries and responses share one format and use port 53. A ZONE is the part of the name space managed by one authority, served by a primary and one or more secondary name servers that copy it by a zone transfer over TCP.
  • There are 13 logical ROOT servers (named A to M) replicated worldwide with anycast. REVERSE lookup of 93.184.216.34 asks for a PTR record under 34.216.184.93.in-addr.arpa (octets reversed). Names are case-insensitive and each label is at most 63 characters.
  • Latency rule: the time to resolve a name is the sum of the RTTs to every server contacted (0 for a cached answer). The HTTP request only starts after the IP address is known, so DNS time adds to the page-load time.
RecordMeaningExample
Ahost name to IPv4 addresswww.example.com -> 93.184.216.34
AAAAhost name to IPv6 addresswww.example.com -> 2606:2800:...
NSauthoritative name server for the domainexample.com -> ns1.example.com
CNAMEalias to canonical namewww.example.com -> web.example.com
MXmail server for the domainexample.com -> mail.example.com
PTRIP address to host name34.216.184.93.in-addr.arpa -> www.example.com

Worked example

Problem. How many servers does the local DNS resolver contact (iteratively) to resolve www.example.com with an empty cache, and which record does mail routing use?

Solution. The resolver asks a ROOT server (gets the .com TLD server), then the .com TLD server (gets the authoritative server for example.com), then the AUTHORITATIVE server (gets the A record): 3 servers. Mail delivery for the domain uses the MX record. Timing: if the three DNS lookups take 10, 20 and 30 ms and the web server is RTT0 = 40 ms away, fetching a page of one base file and 4 images with non-persistent serial HTTP takes 60 + 5 * 2 * 40 = 460 ms; with 4 parallel connections for the images it takes 60 + 2 * 40 + 2 * 40 = 220 ms; with persistent pipelined HTTP it takes 60 + 40 (TCP) + 40 (base) + 40 (all images) = 180 ms.

DNS tree of root, top-level domains and example.com, and the steps a local resolver takes through root, TLD and authoritative servers
DNS hierarchy and resolution: host to resolver is recursive; resolver to root, TLD and authoritative servers is iterative.

HTTP and the web

  • HTTP is a request-response, STATELESS protocol running over TCP (port 80; HTTPS = HTTP over TLS, port 443). Cookies, sessions and hidden fields add state on top of it.
  • METHODS: GET (retrieve), POST (submit data), PUT (replace/store), DELETE, HEAD (headers only, no body), OPTIONS. GET and HEAD are safe; GET, PUT and DELETE are idempotent.
  • STATUS CODE classes: 1xx informational, 2xx success (200 OK, 201 Created), 3xx redirection (301 Moved Permanently, 304 Not Modified), 4xx client error (400 Bad Request, 403 Forbidden, 404 Not Found), 5xx server error (500 Internal Server Error, 503 Service Unavailable).
  • NON-PERSISTENT HTTP (HTTP/1.0): a new TCP connection for every object, costing 2 RTT per object (1 RTT for TCP set-up + 1 RTT for request/response) plus transmission time. PERSISTENT HTTP (HTTP/1.1 default): the connection stays open for several objects; with PIPELINING all requests are sent back to back.
  • WEB CACHING (proxy) with CONDITIONAL GET (If-Modified-Since) returns 304 Not Modified when the cached copy is current, saving bandwidth and delay. Cookies identify returning users and keep session state.
  • HTTP MESSAGE FORMAT: a start line (request line "GET /index.html HTTP/1.1" or status line "HTTP/1.1 200 OK"), header lines (Host is mandatory in HTTP/1.1; also Content-Length, Content-Type, Connection, If-Modified-Since, Cookie and Set-Cookie), a blank line, then an optional body. HTTP/2 multiplexes many streams over one TCP connection; HTTP/3 runs over QUIC (UDP).
  • When the question gives object sizes, ADD the transmission time L / R of each object to the RTT counts. If several objects are sent over one link (pipelined, or parallel connections sharing the bottleneck), their transmission times add up on that link; the RTTs of parallel connections overlap.
  • PROXY CACHE gain: average delay = h * d_cache + (1 - h) * d_origin, where h is the hit ratio. With h = 0.4, cache delay 10 ms and origin delay 200 ms the average is 0.4 * 10 + 0.6 * 200 = 124 ms. A cache also cuts traffic on the access link by the same hit ratio.

Formulas to remember

  • Non-persistent, serial: (1 + n) objects * 2 RTT
  • Non-persistent, n parallel connections: 2 RTT (base) + 2 RTT (all objects)
  • Persistent without pipelining: 1 RTT (TCP) + (1 + n) RTT
  • Persistent with pipelining: 1 RTT (TCP) + 1 RTT (base) + 1 RTT (all objects)
ItemValues to rememberNotes
Safe methodsGET, HEAD, OPTIONSdo not change server state
Idempotent methodsGET, HEAD, PUT, DELETErepeating gives the same server state; POST is not idempotent
2xx200 OK, 201 Created, 204 No Contentrequest succeeded
3xx301 Moved Permanently, 302 Found, 304 Not Modifiedredirect or cached copy valid
4xx400, 401, 403, 404client error
5xx500, 502, 503server error

Worked example

Problem. A page has one base HTML file and 5 images. RTT = 100 ms and transmission time is negligible. Find the load time for each HTTP mode.

Solution. Non-persistent serial: 6 * 2 RTT = 12 RTT = 1200 ms. Non-persistent with 5 parallel connections: 2 RTT (base) + 2 RTT (images) = 4 RTT = 400 ms. Persistent without pipelining: 1 + 6 = 7 RTT = 700 ms. Persistent with pipelining: 1 + 1 + 1 = 3 RTT = 300 ms. With transmission times: base 1000 bytes and 5 images of 50,000 bytes on a 4 Mbps link with RTT 100 ms give Tt(base) = 8000 / 4 x 10^6 = 2 ms and Tt(image) = 400,000 / 4 x 10^6 = 100 ms. Non-persistent serial: (200 + 2) + 5 * (200 + 100) = 1702 ms. Persistent pipelined: 100 (TCP) + 102 (base) + 100 (request all images) + 5 * 100 (images share the link) = 802 ms.

HTTP request and response message formats and a bar chart comparing page load time in RTTs for four HTTP connection modes
HTTP message layout and page-load time for 1 base file + 5 images: 12, 4, 7 and 3 RTT for the four modes.

Email, FTP, sockets and ports

  • EMAIL: a user agent (UA) hands the message to its mail server with SMTP; mail servers relay it to the recipient’s server with SMTP (a PUSH protocol over TCP port 25 that uses persistent connections and 7-bit ASCII text, extended by MIME for attachments). The recipient RETRIEVES mail with POP3 or IMAP (PULL protocols).
  • POP3 (TCP 110): authenticate, list, download and (usually) delete from the server; simple, state is kept on the client. IMAP (TCP 143): mail and folders stay on the server, supports partial download and multiple devices. Web-mail uses HTTP between browser and server.
  • FTP uses TWO TCP connections: a CONTROL connection on port 21 (commands and replies, persistent, out-of-band) and a DATA connection (port 20 in ACTIVE mode, where the server connects back to the client). In PASSIVE mode the client opens both connections, which works through firewalls and NAT. A new data connection is opened for every file transferred. TFTP uses UDP port 69.
  • Other well-known ports: HTTP 80, HTTPS 443, SSH 22, Telnet 23, SMTP 25, DNS 53, DHCP 67/68 (UDP), POP3 110, IMAP 143, SNMP 161 (UDP), BGP 179 (TCP).
  • SOCKET API: a socket is the endpoint of communication between an application process and the transport layer. TCP SERVER: socket() -> bind() -> listen() -> accept() -> recv()/send() -> close(). TCP CLIENT: socket() -> connect() -> send()/recv() -> close(). UDP uses sendto() and recvfrom() with no connect/accept.
  • A TCP connection is identified by the 4-tuple (source IP, source port, destination IP, destination port); the server’s accept() creates a NEW socket for every client while the listening socket stays open. A UDP socket is identified by (destination IP, destination port) only.
  • SMTP DIALOGUE (plain text over TCP): server banner 220, client HELO or EHLO, MAIL FROM, RCPT TO (each answered 250), DATA (answered 354 "start mail input"), the message ending with a line containing only a full stop, then QUIT (221). Reply classes: 2xx success, 3xx more input needed, 4xx temporary failure, 5xx permanent failure (550 mailbox unavailable). The destination server is found with a DNS MX lookup.
  • SMTP vs HTTP: both use persistent TCP connections, but SMTP PUSHES mail and needs 7-bit ASCII (MIME encodes binary attachments), and it puts all objects of a message into one message; HTTP PULLS objects and puts each object in its own response. Secure variants: HTTPS = HTTP over TLS on 443, SSH 22 replaces Telnet 23, and TLS setup adds one or two extra round trips before the first request.
  • Counting sockets and connections: a TCP server with one listening socket and 3 connected clients has 4 sockets; downloading 3 files by FTP opens 1 control connection plus 3 data connections (one per file) = 4 TCP connections, whereas HTTP/1.1 persistent would use a single connection for all three objects.
ProtocolTransport and portRole
SMTPTCP 25send / relay mail (push)
POP3TCP 110download mail to client (pull)
IMAPTCP 143manage mail on the server (pull)
FTPTCP 21 control, 20 datafile transfer, two connections
DNSUDP/TCP 53name resolution
DHCPUDP 67/68automatic IP configuration

Worked example

Problem. Give the sequence of socket calls on a TCP server and explain how a server can serve many clients on the same port.

Solution. Server: socket(), bind() to the port, listen(), then accept() in a loop. Each accept() returns a new connected socket for one client, identified by the 4-tuple (client IP, client port, server IP, server port), so many clients share the server’s single listening port. Mail path: if Alice uses web-mail and Bob uses a POP3 client, Alice’s browser talks HTTP to her mail server, her server relays with SMTP to Bob’s server, and Bob retrieves with POP3 (SMTP is never used to fetch mail).

Mail travelling from the sender user agent through two mail servers by SMTP and to the recipient by POP3 or IMAP, with an SMTP dialogue and a POP3 versus IMAP table
SMTP pushes mail between servers (TCP 25); POP3 (110) and IMAP (143) pull it to the recipient; SMTP command and reply codes.

Exam tips

  • DNS: A = IPv4, MX = mail server, NS = name server, CNAME = alias, PTR = reverse; uses UDP 53 for queries.
  • HTTP page time: non-persistent costs 2 RTT per object; persistent with pipelining costs 1 RTT (TCP) + 1 RTT (base) + 1 RTT (all objects).
  • SMTP pushes mail; POP3 and IMAP pull it; IMAP keeps mail on the server.
  • FTP uses two connections (control 21, data 20); passive mode makes the client open both.
  • TCP server call order: socket, bind, listen, accept; UDP has no listen/accept.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for Application Layer with full explanations. Attempt each question before revealing the answer.

Q1 Classic GATE application layer

Which DNS record type maps a domain to its mail server?

  • A) A
  • B) CNAME
  • C) MX
  • D) PTR
Show answer & explanation

Answer: C

MX (mail exchanger) records name the servers that accept mail for a domain.

Q2

DNS queries use primarily which transport protocol and port?

  • A) TCP 80
  • B) UDP 53
  • C) TCP 25
  • D) UDP 67
Show answer & explanation

Answer: B

DNS queries and responses normally use UDP port 53 (TCP is used for zone transfers).

Q3

The HTTP status code returned when the requested resource is not found is:

  • A) 200
  • B) 301
  • C) 404
  • D) 500
Show answer & explanation

Answer: C

404 Not Found is a client-error (4xx) status.

Q4

A conditional GET for a cached object that has not changed returns the status:

  • A) 200 OK
  • B) 304 Not Modified
  • C) 403 Forbidden
  • D) 503 Service Unavailable
Show answer & explanation

Answer: B

The server answers 304 Not Modified with no body when the cached copy is still current.

Q5

A web page has 1 base file and 5 images. With non-persistent HTTP, serial connections, RTT = 100 ms and negligible transmission time, the total time is:

  • A) 300 ms
  • B) 600 ms
  • C) 1200 ms
  • D) 1000 ms
Show answer & explanation

Answer: C

Each of the 6 objects costs 2 RTT: 6 * 200 ms = 1200 ms.

Q6

For the same page, persistent HTTP with pipelining (including TCP set-up) needs about:

  • A) 200 ms
  • B) 300 ms
  • C) 600 ms
  • D) 700 ms
Show answer & explanation

Answer: B

1 RTT for TCP, 1 RTT for the base file, 1 RTT for all pipelined images = 3 RTT = 300 ms.

Q7

Which protocol lets a user keep messages on the mail server and manage folders from several devices?

  • A) SMTP
  • B) POP3
  • C) IMAP
  • D) FTP
Show answer & explanation

Answer: C

IMAP keeps mail and folder state on the server; SMTP only sends mail and POP3 normally downloads and deletes it.

Q8

FTP uses how many TCP connections for a session, and on which port is the control connection?

  • A) one, port 20
  • B) two, port 21
  • C) two, port 20
  • D) one, port 21
Show answer & explanation

Answer: B

FTP uses a control connection on port 21 and a separate data connection (port 20 in active mode).

Q9

The correct order of socket calls on a TCP server is:

  • A) socket, listen, bind, accept
  • B) socket, bind, listen, accept
  • C) socket, connect, listen, accept
  • D) bind, socket, accept, listen
Show answer & explanation

Answer: B

Create the socket, bind it to a port, mark it passive with listen, then block in accept for clients.

Q10

Which DNS record type is used to translate an IP address back to a host name?

  • A) A
  • B) NS
  • C) MX
  • D) PTR
Show answer & explanation

Answer: D

PTR records live under in-addr.arpa and implement reverse lookup.

Topic drill · 8 questions

8 practice questions — Application Layer

Extra page-specific practice beyond the GATE samples. Attempt all 8, then reveal answers to check your reasoning.

P1

To resolve www.example.com with an empty cache, a local DNS server doing iterative resolution contacts which servers in order?

  • A) authoritative, TLD, root
  • B) root, TLD (.com), authoritative
  • C) TLD, root, authoritative
  • D) root, authoritative, TLD
Show answer & explanation

Answer: B) root, TLD (.com), authoritative

The root refers to the .com TLD server, which refers to the authoritative server that returns the A record.

P2

Which HTTP method asks the server to return only the headers of a resource?

  • A) GET
  • B) POST
  • C) HEAD
  • D) PUT
Show answer & explanation

Answer: C) HEAD

HEAD is like GET but the response has no message body.

P3

An HTTP status code in the 5xx range indicates:

  • A) success
  • B) redirection
  • C) client error
  • D) server error
Show answer & explanation

Answer: D) server error

5xx codes such as 500 and 503 report server-side failures.

P4

A page has 1 base file and 5 images. With non-persistent HTTP, 5 parallel connections for the images, RTT = 100 ms and negligible transmission time, the load time is:

  • A) 300 ms
  • B) 400 ms
  • C) 600 ms
  • D) 1200 ms
Show answer & explanation

Answer: B) 400 ms

2 RTT for the base file + 2 RTT for the parallel images = 4 RTT = 400 ms.

P5

Which protocol is used to send an e-mail from a mail client to its mail server?

  • A) POP3
  • B) IMAP
  • C) SMTP
  • D) HTTP only
Show answer & explanation

Answer: C) SMTP

SMTP pushes mail from the user agent to its server and between servers.

P6

FTP passive mode is useful because:

  • A) it uses UDP
  • B) the client initiates both connections, which works through firewalls and NAT
  • C) it needs only one connection
  • D) it encrypts data
Show answer & explanation

Answer: B) the client initiates both connections, which works through firewalls and NAT

In active mode the server connects back to the client, which many firewalls block.

P7

A TCP connection at a server is uniquely identified by:

  • A) the destination port only
  • B) the source IP address only
  • C) the 4-tuple (source IP, source port, destination IP, destination port)
  • D) the MAC address pair
Show answer & explanation

Answer: C) the 4-tuple (source IP, source port, destination IP, destination port)

Many connections can share the server port; they differ in the client IP and port.

P8

The default port of HTTPS is:

  • A) 80
  • B) 22
  • C) 443
  • D) 8080
Show answer & explanation

Answer: C) 443

HTTPS (HTTP over TLS) uses TCP port 443.

Topic FAQs

What is the difference between recursive and iterative DNS queries?

In a recursive query the contacted server must return the final answer, doing the lookups itself. In an iterative query the server returns the next server to ask and the client continues the search.

Why does HTTP need cookies if it is stateless?

The server does not remember previous requests, so a cookie (set in a response and returned in later requests) lets the server recognise the same user across requests.

How do POP3 and IMAP differ?

POP3 downloads messages (usually deleting them from the server), keeping state on the client. IMAP keeps messages and folders on the server so they can be managed from several devices.

Why does FTP use separate control and data connections?

Commands and replies travel out-of-band on the persistent control connection (port 21), while each file is moved over a separate data connection, which can be set up and closed per transfer.

Quick revision · 9 cards

9 flashcards — Application Layer

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 DNS record types?
Q2 Recursive vs iterative DNS?
Q3 HTTP status classes?
Q4 HTTP non-persistent vs persistent cost?
Q5 Which mail protocols push and which pull?
Q6 FTP connections and ports?
Q7 Ports to remember?
Q8 TCP server socket calls?
Q9 How is a TCP connection identified?