Application Layer
Module 5
Contents
INTRODUCTION
INTRODUCTION
INTRODUCTION
Providing Services
The application layer (like web browsers, email apps) provides services to end users.
Providing Services
Application Layer:
User Services:
Standard and Nonstandard Protocols
Standard Protocols: Are predefined rules and formats that ensure reliable communication between devices and networks. They enable compatibility and seamless data exchange across different systems.
Nonstandard protocols: Are communication rules that don’t follow official or common standards.�They are usually made for specific companies or applications, so they may not work properly with other systems or devices.
Standard and Nonstandard Protocols
Standard Protocols:
Examples: HTTP (web browsing), SMTP (email), FTP (file transfer) and DNS, They show how different services on the Internet follow official, widely accepted communication rules.
Standard and Nonstandard Protocols
Nonstandard Protocols:
Standard and Nonstandard Protocols
Nonstandard Protocols:
Standard and Nonstandard Protocols
Difference:
Application-Layer Paradigms
To use the Internet, two application programs communicate:
The way they interact is defined by two paradigms:
Application-Layer Paradigms
Traditional Paradigm: Client-Server
A server program provides a service, while a client program requests it.
Roles:
How It Works:
Application-Layer Paradigms
Traditional Paradigm: Client-Server
Scenario�Imagine a telephone directory center that helps people find phone numbers.
Application-Layer Paradigms
Traditional Paradigm: Client-Server
Application-Layer Paradigms
Traditional Paradigm: Client-Server
Challenges of Client-Server Paradigm:
Application-Layer Paradigms
Peer-to-Peer (P2P) Paradigm
A peer can send and receive services simultaneously.
How It Works
Application-Layer Paradigms
Peer-to-Peer (P2P) Paradigm
Advantages
Application-Layer Paradigms
Peer-to-Peer (P2P) Paradigm
Examples of P2P Applications
Application-Layer Paradigms
Mixed Paradigm
Advantages
Application-Layer Paradigms
Mixed Paradigm
How It Works
Step 1: Client-Server Communication
A lightweight server is used to locate the address of a peer that can provide the requested service.
Example: A server helps you find which peer has a specific file.
Step 2: Peer-to-Peer Communication
Once the peer is identified, the service is directly exchanged between peers without involving the server.
Example: File sharing happens between two users without the server being involved further.
CLIENT-SERVER PROGRAMMING
a client and a server.
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API):
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API):
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API):
A socket works like a file that can both send and receive data, letting programs communicate over a network just like they read from or write to files.
Without sockets, programs cannot easily communicate over a network because there’s no standard way to send or receive data.
The Socket Interface
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Sockets
Communication Between Processes:
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Sockets
Socket Creation:
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Socket Address
Two-Way Communication:
Socket Addresses:
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Socket Address
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Finding Socket Addresses
How can a client or a server find a pair of socket addresses for communication?
Server Site:
CLIENT-SERVER PROGRAMMING
Application Programming Interface (API): Finding Socket Addresses
How can a client or a server find a pair of socket addresses for communication?
Client Site:
CLIENT-SERVER PROGRAMMING
Using Services of the Transport Layer
UDP Protocol:
CLIENT-SERVER PROGRAMMING
Using Services of the Transport Layer
TCP Protocol:
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Client-Server Interaction:
Client -> Request Datagram -> Server
Server -> Response Datagram -> Client
(if lost, client may resend)
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Sockets Used for UDP:
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Sockets Used for UDP:
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Flow Diagram : Server Process
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Flow Diagram : Server Process
5. Send Response: The server processes the request and sends a response back to the client.
6. Next Iteration: The server then waits for another request, continuing in a loop. The socket is partially filled for each new client connection.
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Flow Diagram : Client Process
CLIENT-SERVER PROGRAMMING
Iterative Communication Using UDP
Flow Diagram
CLIENT-SERVER PROGRAMMING
Iterative Communication Using TCP
Sockets Used in TCP: server uses two sockets
Client -> SYN -> Server
Server -> SYN-ACK -> Client
Client -> ACK -> Server
Client -> Request -> Server
Server -> Response -> Client
CLIENT-SERVER PROGRAMMING
Iterative Communication Using TCP
Flow Diagram: Server Process
CLIENT-SERVER PROGRAMMING
Iterative Communication Using TCP
Flow Diagram: Client Process
CLIENT-SERVER PROGRAMMING
Iterative Communication Using TCP
Flow Diagram
SOCKET INTERFACE PROGRAMMING
SOCKET INTERFACE PROGRAMMING
SOCKET INTERFACE PROGRAMMING
The echo program begins with socket programming, where:
SOCKET INTERFACE PROGRAMMING
Echo Client-Server Program
SOCKET INTERFACE PROGRAMMING
Echo Client-Server Program
Why do we use buffer variables?
SOCKET INTERFACE PROGRAMMING
SOCKET INTERFACE PROGRAMMING
Echo Client-Server Program
TCP Echo Server
TCP Echo Client
Connects to server
Sends message
Receives echo message
Prints it
Closes connection
SOCKET INTERFACE PROGRAMMING
Concurrent Communication
How it works in different languages
SOCKET INTERFACE PROGRAMMING
Concurrent Communication
How it works in different languages
Why concurrency is useful
Standard Client-Server Protocols
Standard Client Server Protocols: World Wide Web and HTTP, FTP, Electronic Mail, Domain Name System (DNS), TELNET, Secure Shell (SSH).
WORLD WIDE WEB
WORLD WIDE WEB
Architecture: Distributed client-server model: A client browser accesses services via servers located at multiple sites.
WORLD WIDE WEB
Example 26.1
Files Involved:
Transactions Needed:
Independence of Files:
WORLD WIDE WEB
Web Client (Browser)
Web Server
WORLD WIDE WEB
Uniform Resource Locator (URL)
Components:
Structure: Combines the four components with specific separators.
Example: http://www.mhhe.com/compsci/forouzan/
WORLD WIDE WEB
Web Documents
Categories:
Static Documents:
WORLD WIDE WEB
Web Documents
Dynamic Documents:
Common tools:
Active Documents:
Tools:
Hyper Text Transfer Protocol (HTTP)
Hyper Text Transfer Protocol
Nonpersistent vs. Persistent Connections
Nonpersistent Connections: A new TCP connection is created for each request-response cycle.
Steps:
Overhead: For N linked objects on the same server:
Browser connects → gets HTML → closes.�Then connects again → gets image1 → closes.�Repeats for image2, image3.
Hyper Text Transfer Protocol
Nonpersistent vs. Persistent Connections
Persistent Connections (Default in HTTP/1.1):
When we open a webpage, the browser uses one TCP connection to get the HTML file, images, CSS, and scripts - all from the same server.
Browser opens 1 connection → gets HTML + 3 images + 1 CSS file → then closes.
Hyper Text Transfer Protocol
Nonpersistent vs. Persistent Connections
Example 26.3: Nonpersistent Connection
Steps:
Result:
Hyper Text Transfer Protocol
Nonpersistent vs. Persistent Connections
Example 26.4: Persistent Connection
Hyper Text Transfer Protocol
Request Message Format
Request message in HTTP consists of the following sections:
Request Line:
Method: Action to do → e.g., GET, POST, PUT, DELETE
URL: Address of the resource
Version: HTTP version used → e.g., HTTP/1.1
Header Lines:
Give extra details about the request (like format, language, or user info).
Common headers: User-Agent, Accept, Authorization
Format: Header-Name: value
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Chrome/122.0
Accept: text/html
Hyper Text Transfer Protocol
Request Message Format
The body in an HTTP request is optional because not all requests need to send data to the server.
Hyper Text Transfer Protocol
Response Message Format
Hyper Text Transfer Protocol
Response Message Format
HyperText Transfer Protocol
HTTP Methods
Hyper Text Transfer Protocol
Common Request Header Names
Common Response Header Names
Hyper Text Transfer Protocol
In HTTP, a client can make a conditional request by adding special headers.
Example: The client asks for /index.html
Server’s Response
Conditional request
Hyper Text Transfer Protocol
Cookies
Cookies are small files a server stores on a client’s browser to remember information about the client.
How they work:
The server creates a cookie with client data and sends it to the browser.
The browser stores the cookie for that server.
On future requests, the browser sends the cookie back, letting the server recognize the client and maintain sessions.
HTTP/1.1 200 OK
Set-Cookie: sessionId=abc123; Expires=Wed, 10 Nov 2025 12:00:00 GMT; Path=/; Secure
Hyper Text Transfer Protocol
Web Caching: Proxy Servers
Hyper Text Transfer Protocol
Web Caching: Proxy Servers
Functionality:
File Transfer Protocol (FTP)
FTP is a standard TCP/IP protocol designed for transferring files between hosts.
It efficiently handles challenges such as differing file name conventions, data representations, and directory structures across systems.
It supports file uploading, downloading, and managing files on the server.
FTP typically uses port 21 for commands and optionally supports secure versions like FTPS or SFTP for encrypted file transfers.
File Transfer Protocol (FTP)
FTP Components:
File Transfer Protocol (FTP)
Control Connection:
File Transfer Protocol (FTP)
Data Connection:
File Transfer Protocol (FTP)
ELECTRONIC MAIL
ELECTRONIC MAIL
Architecture: In the e-mail architecture, the sender (Alice) and receiver (Bob) are connected through two mail servers. These servers store the user’s mailboxes and manage message queues. The communication involves three main agents:
ELECTRONIC MAIL
E-mail scenario:
Alice sends a message to Bob via mail servers, which store the messages. Users interact with the system through three components: a user agent (UA), a message transfer agent (MTA), and a message access agent (MAA). The process involves Alice's UA preparing and sending the message to her mail server. The message is then transferred through the Internet by an MTA client and server to Bob's mail server. Bob retrieves the message using an MAA client and server.
3. Message Access Agent (MAA): This agent allows the user to retrieve messages from the server. It uses a pull mechanism, where the client fetches the messages from the server when needed.
ELECTRONIC MAIL
E-mail scenario:
Storage area where outgoing messages are stored
Storage area where incoming messages are stored
ELECTRONIC MAIL - Format of an e-mail
The User Agent (UA) is a software that helps users send, receive, and manage emails. There are two types:
Sending Mail:
The email consists of:
Receiving Mail:
The UA notifies users of new mail, displaying a list with details like sender, subject, and timestamp. Users can select a message to read.
ELECTRONIC MAIL - Format of an e-mail
Addresses: An email address has two parts:
Mailing List: When you send an email to the mailing list, everyone in the list gets their own copy.
ELECTRONIC MAIL
Message Transfer Agent (MTA) and SMTP
Email uses the client-server paradigm in three ways: two Message Transfer Agents (MTAs) and one Message Access Agent (MAA).
ELECTRONIC MAIL
SMTP command and responses
ELECTRONIC MAIL
Commands and Responses
ELECTRONIC MAIL - Mail Transfer Phases
The mail transfer process occurs in three phases:
1. Connection Establishment
ELECTRONIC MAIL - Mail Transfer Phases
The mail transfer process occurs in three phases:
2. Message Transfer
Client sends commands: Sender → Sender’s Mail
Sender → Sender’s Mail Server → Receiver’s Mail Server → Receiver
3. Connection Termination
ELECTRONIC MAIL – Message access agents
Message Access Agent: POP and IMAP
The third stage of email delivery, involving retrieving messages from the server, uses POP3 or IMAP4. These are pull protocols, in contrast to SMTP’s push protocol.
Simple but limited, POP3 allows clients to connect to the server on TCP port 110, authenticate, and download messages. It does not support mail organization on the server.
More advanced than POP3, IMAP4 allows users to check email headers, search email content, partially download emails, and organize mail on the server with folders.
ELECTRONIC MAIL
MIME (Multipurpose Internet Mail Extensions)
MIME extends the capabilities of electronic mail, enabling it to handle non-ASCII data. Allows email to carry images, audio, videos and attachments.
MIME Headers:
NVT is a standard way of sending characters
ELECTRONIC MAIL
Web-Based Mail allows users to access their email via websites such as Hotmail, Yahoo, and Gmail.
Case I: Alice uses a traditional mail server, while Bob uses a web-based email service. Alice’s email is transferred using SMTP to the server, and then via HTTP to Bob’s browser. Bob logs in to the website, and the email is displayed in HTML format for him to read.
Case II: Both Alice and Bob use web-based servers. Alice sends an email through HTTP to her server, which then forwards it via SMTP to Bob’s server. Bob retrieves the message using HTTP. The message transfer between servers still uses SMTP.
ELECTRONIC MAIL
Web-Based Mail
E-Mail Security:
Email exchanges can be secured using two application-layer protocols: Pretty Good Privacy (PGP) and Secure/Multipurpose Internet Mail Extensions (S/MIME),
TELNET
TELNET (TErminaL NETwork) is a remote logging protocol enabling users to log into remote machines and access resources. It eliminates the need for specialized client/server programs for every service.
Used to configure routers, switches, and other network devices.
Vulnerability:�TELNET transmits data, including credentials, in plaintext, making it vulnerable to hacking. Applications:
TELNET
Local vs Remote Logging:
TELNET
Network Virtual Terminal (NVT) : NVT acts as a translator between different computer systems.
TELNET
Network Virtual Terminal (NVT) :
Options and User Interface:
Concept of NVT
SECURE SHELL (SSH)
SSH is a secure application-layer protocol originally designed to offer enhanced security and versatility.
SECURE SHELL (SSH)
2. SSH Authentication Protocol (SSH-AUTH): This layer authenticates the client to the server after the secure channel is established.
3. SSH Connection Protocol (SSH-CONN): This layer allows multiple activities (like file transfers or remote commands) to happen at the same time over one secure connection.
SECURE SHELL (SSH)
Applications of SSH:
2. File Transfer:
SECURE SHELL (SSH)
Format of SSH Packets:
Domain Name System (DNS)
Domain Name System (DNS)
Domain Name Space:
The domain name space is a hierarchical structure used to organize and manage domain names in the DNS.
Domain Name System (DNS)
Domain Name Space:
Levels:
Example: In www.example.com:
Domain Name System (DNS)
Domain Name Space:
DNS Levels: Example
a.b.c.d.e.school.university.example.com
from right to left:
In this domain, there are 9 nodes/levels.
(root)
|
com
|
example
|
university
|
school
|
e
|
d
|
c
|
b
|
a
Domain Name System (DNS)
Domain Name Space
mail → one node
google → another node
com → another node
Domain Name System (DNS)
Fully Qualified Domain Name (FQDN): A complete and exact address of a computer or host
on the internet.
It includes all parts (labels) of the domain name, written with dots between them.
Example: mail.google.com.
The final dot represents the root of the DNS hierarchy, but in practice, it is usually omitted.
mail → subdomain or specific host
google → second-level domain
com → top-level domain
This full name tells the DNS exactly where the node is located in the hierarchy.
Domain Name System (DNS)
Domains and Subdomains:
A domain represents a subtree in the DNS hierarchy.
Example: example.com is its own subtree.
A subdomain is a branch inside that subtree.
Example: mail.example.com is a subdomain (a branch under example.com).
. ← ROOT (topmost level)
|
com ← Top-Level Domain (TLD)
|
example ← Second-Level Domain
|
mail ← Subdomain
Domain Name System (DNS)
A domain includes the main name and all its subdomains.
For example, the domain example.com includes:
So, a domain = full subtree under example.com.
Domain and Zone
Domain Name System (DNS)
Zone
A zone is the portion of the domain that a DNS server is responsible for.
Example:
Even though they all belong to the same domain (example.com),�they can be split into multiple zones for management.
Domain and Zone
Domain Name System (DNS)
Domain and Zone
Domain Names
Zones
1. edu. zone
2. topUniversity.edu. zone
3. bDept.topUniversity.edu. zone
Domain Name System (DNS)
Resolution in DNS:
1. Recursive Resolution:
Domain Name System (DNS)
Resolution in DNS:
2. Iterative Resolution:
Recursive Resolution Iterative Resolution
Domain Name System (DNS)
Caching in DNS:
Domain Name System (DNS)
Caching in DNS:
Caching : When a server receives a query and gets a response from another server, it stores the mapping (domain name to IP address) in its cache memory.
DNS Caching:
Domain Name System (DNS)
DNS Message Format
Domain Name System (DNS)
DNS Message Format
Domain Name System (DNS)
Dynamic Domain Name System (DDNS)
�Dynamic DNS (DDNS): simplifies updating DNS records(tells how to handle a domain name), such as adding new hosts or changing IP addresses. It automatically sends these updates to the primary DNS server, which then notifies any secondary servers.
Security of DNS: DNS is vital for internet services like web access and email, but it can be attacked in several ways: