Module 11 · 13 min read · Free chapter
Application layer: DNS, HTTP, SMTP, FTP and email
DNS turns names into IP addresses through root, TLD and authoritative servers, mostly over UDP port 53. HTTP is stateless and uses cookies for state; non-persistent HTTP costs 2 RTT per object. SMTP on port 25 pushes mail, POP3 and IMAP pull it, and FTP uses port 21 for control and port 20 for data.
Start from zero: the enquiry counter
Suppose you want to call a sweet shop in another city, but you know only its name. You ring the enquiry counter, the clerk looks in a big register or calls the district office, and you get the phone number. After that you can call the shop directly.
The Internet works the same way. You type a name like www.example.in, but routers understand only IP addresses. A service called DNS plays the clerk: it turns the name into an address, and then your browser talks to the web server using HTTP.
These services live in the application layer, the top layer, where the programs you use every day run. Email, web pages, file transfers and name lookups are all application-layer protocols, built on top of TCP or UDP.
Why it matters. Most exam questions on this layer ask which protocol does which job, which port and transport it uses, and how long a page or a lookup takes. Once you see each protocol as a simple conversation between a client and a server, these questions become easy.
Client-server, peer-to-peer and well-known ports
In the client-server model, a server is always on and has a fixed, known address. Clients come and go and always start the conversation, and two clients never talk to each other directly. The web, email and DNS all follow this model.
In peer-to-peer (P2P), every machine, called a peer, acts as both client and server. File-sharing systems use it, because every new peer also brings extra upload capacity. The cost is that peers join and leave often, which makes the system harder to manage.
Each standard service listens on a well-known port, and exams expect you to know the common ones.
| Protocol | Transport | Server port | Job |
|---|---|---|---|
| HTTP | TCP | 80 | Web pages |
| HTTPS | TCP | 443 | Encrypted web pages |
| DNS | UDP (TCP for large replies) | 53 | Name to address |
| SMTP | TCP | 25 | Sending mail |
| POP3 | TCP | 110 | Downloading mail |
| IMAP | TCP | 143 | Reading mail on the server |
| FTP | TCP | 21 control, 20 data | File transfer |
| SSH | TCP | 22 | Secure remote login |
| Telnet | TCP | 23 | Plain remote login |
| DHCP | UDP | 67 server, 68 client | Address assignment |
Why it matters. A quick look at this table answers many one-mark questions in RRB JE, IT officer and GATE papers. The two traps are DNS, which mostly uses UDP, and FTP, which uses two ports.
DNS: hierarchy, resolution and records
No single computer could hold every name on the Internet, so DNS is spread over many servers arranged as a tree. At the top are the root servers. Below them are top-level domain (TLD) servers for endings such as .com, .org and .in, and below those are the authoritative servers that each organisation runs for its own names.
A host never walks this tree itself. It sends its question to a local DNS server, also called a resolver, usually run by the ISP or the office network. The resolver keeps a cache, so a popular name is answered at once, and each cached record expires after its time-to-live (TTL).
Iterative resolution. The local server asks the root, and the root replies "I don't know, but ask this .in server". The local server then asks the .in server, which refers it to the authoritative server, and finally the authoritative server gives the answer. So the local server makes every query itself, collecting referrals.
Recursive resolution. Here each server takes over the question and asks the next one on behalf of the one that asked it. The answer travels back down the same chain. This puts more load on the upper servers, so in practice the host-to-resolver query is recursive and the resolver's own queries are iterative.
Worked example 1. A host looks up www.example.in with an empty cache. The RTT between the host and its local server is 2 ms, and between the local server and any other DNS server it is 30 ms.
- With iterative resolution the local server asks root, then .in, then the authoritative server, so three RTTs of 30 ms are needed.
- The total time is ms, and the number of messages is .
- If the address of the .in server is already cached, the local server goes straight there, and the time falls to ms.
DNS stores resource records. An A record maps a name to an IPv4 address and AAAA to an IPv6 address. An NS record names the authoritative server, a CNAME gives an alias for another name, and an MX record names the mail server for a domain.
DNS queries normally travel over UDP on port 53, because one short question and answer fit in single packets. When a reply is very large, or a whole zone is copied between servers, DNS uses TCP.
Why it matters. GATE asks for the number of messages or the total time of a lookup under iterative and recursive styles, often with caching. Draw the servers in a row and number each arrow, and the count follows.
HTTP messages, methods, status codes and cookies
HTTP is the protocol of the web. The client, usually a browser, opens a TCP connection to the server's port 80 and sends a request, and the server sends back a response. Each request is handled on its own, with no memory of earlier ones, so HTTP is stateless.
A request starts with a request line of three parts: the method, the URL and the version, for example GET /index.html HTTP/1.1. Next come header lines such as Host and User-Agent, then a blank line, and then an optional body. A response starts with a status line such as HTTP/1.1 200 OK, followed by headers and the requested object.
| Method | Use |
|---|---|
| GET | Fetch an object; data, if any, goes in the URL |
| POST | Send data such as a form in the body |
| HEAD | Like GET but returns only headers |
| PUT | Upload or replace an object at a URL |
| DELETE | Remove an object |
Status codes are grouped by their first digit. 1xx is informational, 2xx is success as in 200 OK, 3xx is redirection as in 301 Moved Permanently, 4xx is a client error as in 404 Not Found, and 5xx is a server error as in 500 Internal Server Error.
Cookies give memory to a stateless protocol. On the first visit, the server sends a Set-Cookie header with an ID, and the browser saves it. On every later request to that site, the browser sends the ID back in a Cookie header, and the server looks up the user's cart or login in its own database.
Why it matters. Method names, status code groups and the stateless nature of HTTP are standard one-mark questions. Cookies are also asked in security and privacy questions, because they can track users across visits.
Persistent and non-persistent HTTP: RTT numericals
A web page is a base HTML file plus many referenced objects such as images. How many TCP connections the browser opens decides how long the page takes. The key unit is the round-trip time (RTT).
Non-persistent HTTP. A new TCP connection is opened for every object. One RTT goes in the TCP handshake, and one more RTT goes in sending the request and receiving the start of the reply. So each object costs about 2 RTT plus its transmission time.
Persistent HTTP. The server leaves the connection open after replying, and later objects use the same connection. Without pipelining, the client sends each new request only after the previous reply, so each further object costs 1 RTT. With pipelining, it sends all requests at once, so all the further objects together cost about 1 RTT.
HTTP/1.0 is non-persistent by default, while HTTP/1.1 is persistent by default. Browsers also open a few parallel connections to cut the time of non-persistent fetches.
Worked example 2. A page has one base HTML file and 10 small images on the same server. The RTT is 50 ms, and transmission times are small enough to ignore.
| Method | RTTs | Time |
|---|---|---|
| Non-persistent, one at a time | 1,100 ms | |
| Non-persistent, 10 parallel connections for images | 200 ms | |
| Persistent without pipelining | 600 ms | |
| Persistent with pipelining | 150 ms |
- In every method the base file needs 2 RTT, because the connection must be opened first.
- Only after the base file arrives does the browser know which images to ask for.
- If the name must first be looked up in DNS, the lookup time is added once at the start.
If transmission time is not negligible, add it for each object. For example, a 100 KB object on a 10 Mbps link adds s, which is 80 ms, to the time of that object.
Why it matters. These timing questions are favourites because they test both TCP and HTTP together. Draw a timeline for the first two objects, and the pattern for the rest becomes clear.
Email with SMTP, POP3 and IMAP, and file transfer with FTP
An email system has three parts: user agents such as a mail app, mail servers that hold mailboxes, and the protocols between them. Sending and reading use different protocols. That is the key idea to remember.
SMTP pushes mail. The sender's user agent hands the message to its own mail server, and that server opens a TCP connection to the receiver's mail server on port 25 and delivers it. The two servers talk in short text commands: HELO to greet, MAIL FROM and RCPT TO for the addresses, DATA for the message, and QUIT to finish.
SMTP was built for 7-bit ASCII text. So photos, PDFs and text in Hindi or other scripts are encoded with MIME, which adds headers describing the content type and encoding. The mail then waits in the receiver's mailbox on the server.
POP3 and IMAP pull mail. With POP3 (port 110), the user agent usually downloads the messages and deletes them from the server, so they live on one device. With IMAP (port 143), mail and folders stay on the server, so a phone and a laptop see the same mailbox, and webmail simply uses HTTP between the browser and the server.
FTP transfers files and uses two TCP connections. The control connection to server port 21 stays open for the whole session and carries commands such as USER, PASS, LIST, RETR to download and STOR to upload. For every file or directory listing, a separate data connection is opened, from server port 20 in active mode, and closed when that transfer ends.
Because commands travel on a different connection from the data, FTP is said to send control information out-of-band. The server must also remember the user's login and current directory during the session, so FTP is stateful, unlike HTTP. In passive mode, the client opens the data connection instead, which works better through firewalls and NAT.
Why it matters. "Which protocol is push and which is pull?", "Which ports does FTP use?" and "Is FTP stateful?" are common questions. Remember the email path as push, push, pull: SMTP twice, then POP3 or IMAP.
Descriptive lens: how written papers ask this
Written papers for IT officer posts, state Assistant Programmer exams and university-level tests ask about the application layer in four ways:
- Explain how DNS turns a name into an address, with a diagram of iterative and recursive resolution.
- Compare persistent and non-persistent HTTP and calculate page load times.
- Trace the path of an email from sender to receiver, naming each protocol on the way.
- Describe FTP's two connections and say why FTP is stateful.
Practice questions (our own, not previous-year questions).
- Explain the DNS hierarchy and compare iterative and recursive resolution with a labelled diagram. (10 marks)
- A page has a base file and 5 images. With an RTT of 40 ms, find the load time under non-persistent and persistent HTTP, with and without pipelining. (10 marks)
- Describe how an email travels from a sender to a receiver who reads it on two devices. Explain the roles of SMTP, MIME and IMAP. (15 marks)
Answer plan for question 3.
- Begin by naming the three parts of the system, which are user agents, mail servers and the protocols between them.
- Explain that the sender's user agent pushes the message to its own mail server using SMTP.
- Explain that this server finds the receiver's mail server through the MX record in DNS and pushes the message there with SMTP over TCP port 25.
- Mention that attachments and non-English text are encoded with MIME because SMTP carries only 7-bit text.
- Explain that the receiver reads the mail with IMAP, which keeps messages and folders on the server so that both devices see the same mailbox.
- Conclude that POP3 would suit only a single device, because it usually downloads and deletes the mail.
Quick revision
- In client-server the server is always on, and in peer-to-peer every peer is both client and server.
- HTTP uses port 80, HTTPS 443, SMTP 25, POP3 110, IMAP 143, SSH 22 and Telnet 23.
- DNS mostly uses UDP port 53, and FTP uses port 21 for control and 20 for data.
- DNS runs from root to TLD to authoritative servers, and resolvers cache answers for their TTL.
- Iterative resolution returns referrals, while recursive resolution returns the final answer.
- The A record gives an IPv4 address, AAAA an IPv6 address, NS the name server, CNAME an alias and MX the mail server.
- HTTP is stateless, and cookies add state with the Set-Cookie and Cookie headers.
- Status code 200 means OK, 301 means moved, 404 means not found and 500 means a server error.
- Non-persistent HTTP costs 2 RTT per object, and persistent HTTP with pipelining fetches the rest in about 1 RTT.
- SMTP pushes mail, POP3 and IMAP pull it, and MIME encodes attachments.
- FTP keeps one control connection open and opens a data connection per file, so it is stateful and out-of-band.