Application Layer Fundamentals
The application layer is the highest layer of the OSI reference model. It provides network services directly to users and is the interface through which users interact with the network.
1.1 Serving Users Directly: The “Front Desk” of the Network
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The application layer faces the user directly and provides the various networked application services. It works like the waiter in a restaurant: the customer does not need to know how the kitchen operates.
The Role of the Application Layer
The restaurant analogy:
| Layer | Restaurant analogy | Network layer | Function |
|---|---|---|---|
| Application layer | The waiter | Application layer | Serves the customer or user directly |
| Transport layer | The kitchen runner | Transport layer | Carries the dishes or the data |
| Network layer | The purchasing department | Network layer | Transports the ingredients or routes the packets |
| Link layer | The supplier | Link layer | Provides the ingredients or the transmission medium |
| Physical layer | The delivery vehicle | Physical layer | Physical transport or signal transmission |
Users only ever deal with the application layer:
- Users: browse pages, send mail, download files
- Application layer: provides the interface and the function for those services
- Lower layers: support it behind the scenes, and the user never has to care
The Types of Service the Application Layer Provides
1. File services
Like borrowing and returning books at a library:
- 📁 File transfer: uploading and downloading files (FTP)
- 📂 File sharing: sharing files among many people (cloud drives)
- 📄 File synchronisation: keeping files in step across devices (Dropbox)
2. Communication services
Like the post office and the telephone:
- 📧 Electronic mail: sending and receiving mail (SMTP, POP3)
- 💬 Instant messaging: real-time chat (WeChat, QQ)
- 📞 Video conferencing: remote meetings (Zoom, Tencent Meeting)
3. Information lookup
Like a library catalogue:
- 🌐 Web browsing: visiting sites (HTTP)
- 🔍 Search engines: searching for information (Baidu, Google)
- 📊 Database queries: looking up data (SQL)
4. Remote services
Like a remote control:
- 🖥️ Remote login: accessing a computer remotely (SSH)
- 🎮 Remote control: operating a device remotely (RDP)
- 🔧 Remote management: administering servers remotely
2.1 The Client/Server Model (C/S)
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The C/S model (Client/Server) is a centralised model for networked applications in which the client actively requests a service and the server passively provides it. It works like a restaurant: the customer (the client) orders, the cook (the server) prepares the food.
How the C/S Model Works
The restaurant ordering analogy:
The customer (the client): reads the menu (learns what is on offer) → orders (issues the request) → waits (waits for the response) → eats (uses the service).
The cook (the server): takes the order (receives the request) → cooks (processes the request) → serves the dish (returns the result) → waits for the next order (waits for a new request).
The C/S model in the network:
The client (the active side): a browser visiting a site, a mail client sending and receiving mail, a file client uploading and downloading — it initiates requests.
The server (the passive side): a web server serving pages, a mail server processing mail, a file server storing files — it responds to requests.
Characteristics of the C/S Model
1. A clear structure
Like a restaurant with clearly divided roles:
| Role | Responsibility | Network role |
|---|---|---|
| The customer | Orders and eats | The client: requests the service |
| The waiter | Takes the order and serves it | The application layer: processes the request |
| The cook | Cooks the food | The server: provides the service |
2. Centralised management
Like a restaurant managed under one roof:
- The server manages all the resources centrally (files, data, services)
- The client does not have to manage resources
- The server controls access rights (who may access what)
3. Easy maintenance
Like a restaurant that is simple to maintain:
- Only the server has to be maintained (upgraded, repaired, optimised)
- The client needs no maintenance (the user simply uses it)
- Problems are easy to locate (they are on the server)
4. Good security
Like a restaurant with controlled access:
- The server controls access rights
- A single security policy applies
- Monitoring and auditing are straightforward
Typical Applications of the C/S Model
Common C/S applications:
1. Web browsing (the most typical)
- Client: the browser (Chrome, Firefox)
- Server: the web server (Apache, Nginx)
- Process: the browser visits a site and the server returns the page
2. Mail services
- Client: the mail client (Outlook, Foxmail)
- Server: the mail server (Exchange, Postfix)
- Process: the client sends and receives mail and the server processes it
3. File transfer
- Client: the FTP client
- Server: the FTP server
- Process: the client uploads and downloads files and the server stores them
4. Database access
- Client: the application
- Server: the database server (MySQL, Oracle)
- Process: the application queries the data and the database returns the result
The Advantages and Disadvantages of the C/S Model
Advantages:
✅ Centralised management: resources are stored centrally and are easy to manage ✅ A clear structure: the responsibilities of the client and the server are explicit ✅ Easy maintenance: only the server side has to be maintained ✅ Good security: the server controls access in one place ✅ Predictable performance: the server’s performance determines the quality of service
Disadvantages:
❌ Limited scalability: the server’s performance caps the performance of the whole system ❌ A single point of failure: if the server fails, every client is affected ❌ Higher cost: powerful server hardware is required ❌ Dependence on the server: the client depends entirely on the server
2.2 The Peer-to-Peer Model (P2P)
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The P2P model (Peer-to-Peer) is a distributed model for networked applications in which every node is both a client and a server, and the nodes talk to each other directly. It works like a circle of friends: everyone is a sharer (a server) and a viewer (a client) at the same time.
How the P2P Model Works
The circle of friends analogy:
Each person (each node): publishes content (serving as a server), reads content (acting as a client), and forwards content (being both server and client). There is no central platform; the nodes share directly with one another.
P2P in the network: node A serves file 1 (acting as a server) and downloads file 2 (acting as a client); node B serves file 2 and downloads file 1. The nodes talk to each other directly, with no central server involved.
Characteristics of the P2P Model
1. Peers are equal
Like friends in a circle, who are all on equal terms:
- Every node has the same standing
- Every node is both a client and a server
- There is no master/slave relationship
2. Distribution
Like content that is spread across everyone in the circle:
- Resources are spread across all the nodes
- There is no central server
- Every node contributes part of the resources
3. Strong scalability
Like a circle that livens up as more people join:
- More nodes means more resources
- More nodes means faster downloads
- Performance is not limited by any single node
4. Good fault tolerance
Like a circle where the others are still visible when one person is away:
- The failure of a single node does not affect the whole
- Resources have multiple copies
- The system switches to other nodes automatically
Typical Applications of the P2P Model
Common P2P applications:
1. File sharing (the most typical)
- BitTorrent: downloading films and software
- eMule: file sharing
- Characteristic: the files are spread across many nodes and downloaded in parallel, which is fast
2. Instant messaging
- Skype: voice and video calls
- QQ, WeChat: file transfer in P2P mode
- Characteristic: the nodes talk directly, with no central server
3. Blockchain
- Bitcoin: digital currency
- Ethereum: smart contracts
- Characteristic: decentralised, with all the nodes maintaining the ledger together
4. Distributed computing
- SETI@home: the search for extraterrestrial signals
- Folding@home: protein folding computation
- Characteristic: the work is spread across many nodes and computed in parallel
The Advantages and Disadvantages of the P2P Model
Advantages:
✅ Strong scalability: the more nodes there are, the more capable the service is ✅ Good fault tolerance: the failure of a single node does not affect the whole ✅ Low cost: no expensive central server is needed ✅ Abundant resources: the resources contributed by the nodes pool together ✅ Fast downloads: several nodes are downloaded from in parallel
Disadvantages:
❌ Complex management: with no centre, management is difficult ❌ A security challenge: the nodes are autonomous, so a single security policy is hard to enforce ❌ Copyright problems: file sharing may infringe copyright ❌ Uncertain reliability: it depends on the quality of each node ❌ Hard to control: there is no central server in control
2.3 C/S Compared with P2P
| Feature | The C/S model | The P2P model | Analogy |
|---|---|---|---|
| Structure | Centralised | Distributed | The restaurant against the circle of friends |
| Central node | There is a server | There is no centre | The cook against everyone |
| Where resources live | On the server | Spread across the nodes | The kitchen against each person’s own home |
| Scalability | Limited by the server | Grows with the number of nodes | Limited by the kitchen, versus the better it gets the more people join |
| Reliability | Depends on the server | Fault tolerant | The cook falling ill affects the restaurant, versus one person being absent not affecting the circle |
| Management difficulty | Easy to manage | Hard to manage | Running a kitchen against a circle that needs no management |
| Security | Easy to control | Hard to control | Kitchen hygiene under control against hygiene that differs from home to home |
| Cost | High (a server) | Low (no centre) | The cost of building a kitchen against not building one |
| Typical use | Conventional services | Peer sharing | Ordering a dish against sharing |
How to choose:
When to use the C/S model: when resources need centralised management, a uniform security policy, and a reliable quality of service, and when the resources and the user base are relatively stable.
When to use the P2P model: when resources are spread across many nodes, when scalability and fault tolerance matter, and when the user base is large and dynamic and the budget limited.
3.1 What an Application Layer Protocol Is
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
An application layer protocol defines the rules and the formats of communication at the application layer, like the menu and the service procedure of a restaurant.
The Role of a Protocol
The restaurant specification analogy:
| Restaurant specification | Application layer protocol | Function |
|---|---|---|
| The format of the menu | The data format | Defines how the data is organised |
| The ordering procedure | The request format | Defines how a request is issued |
| The serving procedure | The response format | Defines how a response is returned |
| The service procedure | The communication procedure | Defines the steps of the exchange |
What a protocol contains:
- Data format: how the data is organised (JSON, XML, HTML)
- Request format: how a request is issued (GET, POST)
- Response format: how a response is returned (status codes, data)
- Error handling: what happens when something goes wrong (error codes, retries)
- State management: how session state is managed (cookies, sessions)
3.2 Common Application Layer Protocols
File Transfer Protocols
FTP (File Transfer Protocol)
Like sending and receiving parcels by courier:
| Function | Analogy | What the protocol does |
|---|---|---|
| Upload a file | Posting a parcel | The client uploads to the server |
| Download a file | Collecting a parcel | The client downloads from the server |
| Manage files | Tidying the parcels | Creating, deleting, and moving files |
| Access control | Checking identity | Verifying the user’s permissions |
Characteristics:
- Ports: 20 (data), 21 (control)
- Supports anonymous access and authenticated access
- Supports listing, uploading, downloading, and deleting files
HTTP (Hypertext Transfer Protocol)
Like borrowing a book from a library:
| Function | Analogy | What the protocol does |
|---|---|---|
| GET | Borrowing a book | Retrieves the content of a page |
| POST | Returning a book with a filled-in form | Submits data to the server |
| PUT | Updating the record of a book | Updates the resource |
| DELETE | Cancelling the loan | Deletes the resource |
Characteristics:
- Ports: 80 (HTTP), 443 (HTTPS)
- A stateless protocol (every request is independent)
- Supports several request methods
Mail Protocols
SMTP (Simple Mail Transfer Protocol)
Like posting a letter at the post office:
What SMTP is responsible for:
- Sender → the sender’s post office (the mail is submitted)
- The sender’s post office → the recipient’s post office (the mail is carried)
Characteristics:
- Port: 25
- Responsible for sending mail
- Push model (the mail is pushed out)
POP3 (Post Office Protocol)
Like going to the post office to collect your letters:
What POP3 is responsible for: the recipient collects the mail at the post office and keeps it locally after downloading it.
Characteristics:
- Port: 110
- Responsible for receiving mail
- Pull model (the mail is fetched actively)
- Delete after download (optional)
IMAP (Internet Message Access Protocol)
Like reading your letters at the post office:
What IMAP is responsible for: the recipient reads the mail at the post office without downloading it; the mail stays on the server.
Characteristics:
- Port: 143
- Responsible for receiving mail
- The mail stays on the server
- Supports access from several devices
Name Resolution Protocols
DNS (Domain Name System)
Like a telephone directory:
Scenario: you want to call Zhang San but you do not have the number.
The lookup process:
- You check the address book (the local DNS cache)
- You do not find it, so you ask directory enquiries (the DNS server)
- The directory gives you the number:
13800138000 - You make the call (visit the site)
DNS resolution:
- Query the IP address of
www.baidu.com - DNS returns:
202.108.22.5 - Visit the site using the IP address
Characteristics:
- Port: 53
- UDP (fast lookups)
- A distributed database (servers at several levels)
- Caching (fewer queries)
Remote Service Protocols
SSH (Secure Shell)
Like a remote control:
Scenario: you are at home and you want to control the office computer remotely.
The SSH connection:
- Your computer (the client)
- Connect over SSH to the office computer (the server)
- Work as if you were sitting in front of it
- The traffic is encrypted, so it cannot be eavesdropped
Characteristics:
- Port: 22
- Encrypted communication (secure)
- Supports remote login
- Supports file transfer (SCP)
Telnet
Like a remote control, in the insecure version:
Telnet is similar to SSH but without encryption: it provides remote login over plaintext, which is insecure, and it is rarely used today.
Characteristics:
- Port: 23
- No encryption (insecure)
- A historical protocol
- Superseded by SSH
3.3 The Relationship Between Protocols and Ports
Each application protocol uses a specific port:
Just as each service has its own telephone number:
| Service | Port | Protocol | Transport layer |
|---|---|---|---|
| Web browsing | 80 | HTTP | TCP |
| Secure web | 443 | HTTPS | TCP |
| File transfer | 21 | FTP control | TCP |
| File transfer | 20 | FTP data | TCP |
| Sending mail | 25 | SMTP | TCP |
| Receiving mail | 110 | POP3 | TCP |
| Receiving mail | 143 | IMAP | TCP |
| Name resolution | 53 | DNS | UDP |
| Remote login | 22 | SSH | TCP |
| Remote login | 23 | Telnet | TCP |
Why a specific port is needed:
- The client knows which port to connect to
- The server knows which protocol to handle the traffic with
- It avoids a confusion of protocols
Example 1: The Full Process of Visiting a Website
Let us look at the full process of visiting a website from the point of view of the application layer:
What the user does:
- Opens the browser
- Types the address
www.baidu.com - Presses Enter
Application layer (the HTTP protocol):
- The browser builds the HTTP request:
GET / HTTP/1.1,Host: www.baidu.com,User-Agent: Chrome - DNS resolution: the browser looks up
www.baidu.com→202.108.22.5
Transport layer (TCP):
- The TCP connection is established (the three-way handshake): browser port 54321 → server port 80
Network layer (IP):
- IP routing: client IP → server IP (
202.108.22.5)
The server:
- Receives the HTTP request
- Processes the request (querying the database, generating the page)
- Builds the HTTP response:
HTTP/1.1 200 OK,Content-Type: text/html, body<html>...</html>
The data returns:
- HTTP response → TCP transport → IP routing → back to the client
The browser:
- Parses the HTML
- Renders the page
- Displays it to the user
Example 2: The Process of Sending Mail
What the user does:
- Opens the mail client (Outlook)
- Writes the message: recipient
friend@example.com - Clicks send
Application layer (the SMTP protocol):
- The mail client builds the SMTP commands:
MAIL FROM: you@example.com,RCPT TO: friend@example.com,DATA: <the body of the message>
Transport layer (TCP):
- Connects to the SMTP server (port 25)
Network layer (IP):
- Routes to the mail server
The mail server:
- Receives the message
- Looks up the location of the recipient’s mailbox
- Forwards the message to the recipient’s mail server
The recipient’s mail server:
- Receives the message
- Stores it in the recipient’s mailbox
The recipient reads the mail:
- Opens the mail client
- Connects to the POP3 server (port 110)
- Downloads the mail
- Displays the content
Example 3: A P2P File Download
What the user does:
- Opens the BitTorrent client
- Adds the torrent file
- Starts the download
The P2P process:
- The torrent file is parsed and the file information is obtained: the name
movie.mp4, the size 1GB, divided into 1000 pieces, and the list of peers A, B, C, D… - Several peers are connected to: peer A has pieces 1-100, peer B has pieces 101-200, peer C has pieces 201-300, peer D has pieces 301-400
- Parallel download: the pieces are downloaded from peers A/B/C/D at the same time, which is fast
- Uploading at the same time: once you have downloaded pieces 1-100, other peers need them and you upload them — you are both a client and a server
- The download finishes: all the pieces are downloaded, combined into the complete file, and you go on uploading to the other peers
Exercise 1
How do the C/S model and the P2P model differ, and what scenarios suit each of them?
Approach
Compare the two models along the axes that decide which one to use: structure, where resources live, the roles of the nodes, scalability, and reliability. Then map each to its scenarios.
Steps
- Compare the structural characteristics.
- Compare where resources are stored.
- Compare the roles of the nodes.
- Compare scalability.
- Compare reliability.
- List the scenarios for C/S and then for P2P.
Answer
The main differences are:
-
Structure:
- C/S: centralised, with a central server
- P2P: distributed, with no central node
-
Where resources are stored:
- C/S: the resources are concentrated on the server
- P2P: the resources are spread across the nodes
-
The roles of the nodes:
- C/S: the roles of client and server are distinct
- P2P: every node is both a client and a server
-
Scalability:
- C/S: limited by the performance of the server
- P2P: grows as the number of nodes grows
-
Reliability:
- C/S: depends on the server, so a single point of failure has a large effect
- P2P: fault tolerant, so the failure of one node has a small effect
Where C/S suits:
- Web browsing: the pages are concentrated on the server
- Mail services: the mail is concentrated on the mail server
- File services: the files are concentrated on the file server
- Database services: the data is concentrated on the database server
Characteristic: the resources are centralised and need unified management, with a stable user base.
Where P2P suits:
- File sharing: the files are spread across many nodes
- Instant messaging: the nodes talk directly to one another
- Blockchain: decentralised applications
- Distributed computing: the work is spread across many nodes
Characteristic: the resources are dispersed and high scalability is needed, with a dynamic user base.
Exercise 2
What is the role of an application layer protocol? Give some common examples.
Approach
State the role as the definition of the rules of communication, list the five things a protocol has to specify, and then give a concrete protocol from each family with its port.
Steps
- State the role of an application layer protocol.
- List the five things a protocol specifies.
- Give the file transfer protocols.
- Give the mail protocols.
- Give the name resolution protocol.
- Give the remote service protocols.
Answer
The role of an application layer protocol:
An application layer protocol defines the rules and the formats of communication at the application layer, like the service specification of a restaurant:
- Data format: defines how the data is organised
- Request format: defines how a request is issued
- Response format: defines how a response is returned
- Error handling: defines what happens when something goes wrong
- State management: defines how the session is managed
Common protocol examples:
File transfer protocols:
- FTP: file upload and download (ports 21/20)
- HTTP: web browsing (port 80)
- HTTPS: secure web browsing (port 443)
Mail protocols:
- SMTP: sending mail (port 25)
- POP3: receiving mail (port 110)
- IMAP: mail access (port 143)
Name resolution:
- DNS: name resolution (port 53, UDP)
Remote services:
- SSH: secure remote login (port 22)
- Telnet: remote login (port 23)
What every protocol has in common:
- It uses a specific port
- It defines a data format
- It defines a communication procedure
- It defines error handling
Exercise 3
What is the role of the DNS protocol? Describe the DNS resolution process.
Approach
State the role of DNS, then walk down the hierarchy from the client to the root, the top-level, and the authoritative servers, and finally describe the return path.
Steps
- State the role of the DNS protocol.
- Describe the local cache lookup.
- Describe the local DNS server lookup.
- Describe the root server lookup.
- Describe the top-level domain server lookup.
- Describe the authoritative server lookup.
- Describe the return of the result.
Answer
The role of the DNS protocol:
DNS (the Domain Name System) resolves domain names into IP addresses, in the same way a telephone directory turns a name into a number.
The DNS resolution process:
Scenario: the user visits www.baidu.com
-
The local cache lookup:
- The browser checks the local cache
- If there is a cached entry, it is used directly
- If not, the lookup continues
-
The local DNS server lookup:
- The browser queries the local DNS server
- The local DNS server checks its cache
- If there is a cached entry, the IP address is returned
- If not, the lookup continues
-
The root DNS server lookup:
- The local DNS server queries a root server
- The root server returns the addresses of the top-level domain servers
-
The top-level domain server lookup:
- The local DNS server queries a top-level domain server
- It returns the address of the authoritative server
-
The authoritative server lookup:
- The local DNS server queries the authoritative server
- The authoritative server returns the IP address: 202.108.22.5
-
The result is returned:
- The local DNS server returns the IP address to the browser
- The browser caches the result
- The site is visited using the IP address
The analogy:
Like looking up a telephone number:
- First check the address book (the local cache)
- If it is not there, ask directory enquiries (the DNS server)
- The directory looks up the number and returns it
- Dial the number (visit the site)
Exercise 4
How do HTTP and FTP differ, and what scenarios suit each of them?
Approach
Compare them on the dimensions that matter in practice — purpose, ports, connection model, data types, how they are driven, and security — and then map each to its scenarios.
Steps
- Compare the purpose.
- Compare the ports.
- Compare the connection model.
- Compare the data types.
- Compare the way operations are expressed.
- Compare security.
- State the selection rule.
Answer
The main differences are:
-
Purpose:
- HTTP: web browsing, retrieving the content of pages
- FTP: file transfer, uploading and downloading files
-
Ports:
- HTTP: port 80 (443 for HTTPS)
- FTP: port 21 (control), 20 (data)
-
Connection model:
- HTTP: short-lived connections, closed once the request and response are done
- FTP: persistent connections, with the session state maintained
-
Data types:
- HTTP: mainly carries web content such as HTML and images
- FTP: carries files of any type
-
How operations are expressed:
- HTTP: request methods such as GET and POST
- FTP: commands such as upload, download, delete, and list
-
Security:
- HTTP: plaintext (encrypted by HTTPS)
- FTP: plaintext (encrypted by SFTP)
Where HTTP suits:
- Web browsing: visiting sites
- API calls: calling web services
- Form submission: submitting data
- Content retrieval: fetching pages, images, and so on
Where FTP suits:
- Large file transfers: uploading and downloading big files
- File management: creating, deleting, and moving files
- Site maintenance: uploading the files of a site to a server
- Backup and restore: backing files up to a remote server
How to decide:
- If you need to browse pages → use HTTP
- If you need to transfer files → use FTP
- If you need to manage files → use FTP
- If you need to retrieve content quickly → use HTTP
