1 of 122

Application Layer

Module 5

2 of 122

Contents

  • Introduction, Client-Server Programming, Socket interface programming, Standard Client Server Protocols: World Wide Web and HTTP, FTP, Electronic Mail, Domain Name System (DNS), TELNET, Secure Shell (SSH)

  • Text Book 1: Chapter 25.1,25.2 Chapter 26

3 of 122

INTRODUCTION

  • The application layer is a communication interface between users and application programs that sits at the top of the Open Systems Interconnection (OSI) model.

  • The application layer provides services to the user.

  • It uses a logical connection, allowing the two application layers to communicate as if they are directly connected, even if no physical connection exists.

  • This allows them to send and receive messages easily.

4 of 122

INTRODUCTION

5 of 122

INTRODUCTION

  • For example, a scientist at Sky Research (Alice) wants to order a book from Scientific Books (Bob).

  • From Alice's and Bob's perspectives, they think they are directly connected and can send messages to each other.

  • However, in reality, the communication passes through many devices like routers (R2, R4, R5, R7) and switches, as shown in the figure.

  • The application layer hides this complexity, making communication feel simple and direct.

6 of 122

Providing Services

  • Traditional Networks: Each layer or component provides a specific service to the layer above it.� Eg: The telephone network’s hardware provides voice service to users.

  • Internet Design: The lower layers (like IP) provide data transfer services to the upper layers (like TCP, HTTP).

The application layer (like web browsers, email apps) provides services to end users.

  • Protocol Flexibility: The Internet allows new protocols to be added or old ones to be replaced. Protocols work smoothly with lower layers and adjust higher layers when needed.

7 of 122

Providing Services

Application Layer:

    • The top layer of the Internet protocol suite.
    • It receives services from the transport layer but doesn’t provide services to other layers.
    • Adding or removing application protocols is easy.

User Services:

    • The application layer interacts directly with users, providing the services they need to use the Internet, such as email, web browsing, or file transfer. Its flexibility has led to the continuous addition of new application protocols over time.

8 of 122

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.

9 of 122

Standard and Nonstandard Protocols

Standard Protocols:

  • These are official, widely used, and documented by Internet authorities (e.g., IETF).
  • Built into operating systems like Windows or UNIX.
  • Ensure smooth communication and consistency across the Internet.

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 protocols are used in all the four layers of the TCP/IP model — from the Network Interface layer up to the Application layer

10 of 122

Standard and Nonstandard Protocols

Nonstandard Protocols:

  • Custom-made protocols created for specific needs, usually for private use.

  • Do not need approval from Internet authorities if not shared publicly.

  • Often used by companies for internal communication.

  • Allow companies to develop their own systems to communicate globally.

  • Example: Custom Chat Application Protocol, IoT Device Communication Protocol:

11 of 122

Standard and Nonstandard Protocols

Nonstandard Protocols:

  • Require two custom programs to interact with the transport layer and provide services:

    • Communication over a network always involves two sides: a sender (client) and a receiver (server).
    • Each side needs a custom program to handle the specific nonstandard protocol.
    • One program manages how data is sent, while the other program handles the reception and interpretation of that data.
    • These two programs ensure that both ends of the communication can understand and use the nonstandard protocol.

12 of 122

Standard and Nonstandard Protocols

Difference:

  • Standard Protocols: Universal, pre-defined, and widely supported.

  • Nonstandard Protocols: Custom-designed for specific purposes, flexible but limited to specific environments.

13 of 122

Application-Layer Paradigms

To use the Internet, two application programs communicate:

  • One on a computer somewhere and another on a different computer.
  • These programs exchange messages via the Internet.

The way they interact is defined by two paradigms:

  • Traditional Paradigm: Client-Server
  • New Paradigm: Peer-to-Peer

14 of 122

Application-Layer Paradigms

Traditional Paradigm: Client-Server

A server program provides a service, while a client program requests it.

Roles:

  • The server is always running, waiting for clients.
  • The client starts only when the user needs a service.

How It Works:

  • The server program continuously provides services.
  • Clients connect to the server temporarily to request and receive services.
  • Each client-server interaction requires two separate programs: one for the server and one for the client.

15 of 122

Application-Layer Paradigms

Traditional Paradigm: Client-Server

Scenario�Imagine a telephone directory center that helps people find phone numbers.

  • The directory center acts as the server:
    • It is always ready and available to provide phone numbers.
    • It "waits" for people to call and request information.
  • A subscriber (caller) acts as the client:
    • The subscriber only calls the center when they need a specific phone number.
    • Once the request is fulfilled, the connection ends.

16 of 122

Application-Layer Paradigms

Traditional Paradigm: Client-Server

17 of 122

Application-Layer Paradigms

Traditional Paradigm: Client-Server

Challenges of Client-Server Paradigm:

  1. Server Load:
    1. Servers handle all the communication load.
    2. A server must be powerful enough to handle multiple clients.
    3. If too many clients connect, even strong servers can become overwhelmed.
  2. Cost and Maintenance:
    • The service provider must invest in a powerful server.
    • To justify the cost, the server usually needs to generate income.

18 of 122

Application-Layer Paradigms

Peer-to-Peer (P2P) Paradigm

  • Unlike the client-server model, there is no dedicated server running all the time.
  • Peers (computers) share responsibilities, providing and receiving services as needed.

A peer can send and receive services simultaneously.

How It Works

  • Any computer connected to the Internet can act as both a service provider and a service requester.
  • Example:
    • If a user wants to share a file, they don’t need to set up a server.
    • Their computer temporarily becomes a provider when another user requests the file.

19 of 122

Application-Layer Paradigms

Peer-to-Peer (P2P) Paradigm

Advantages

  1. Scalability: Easily handles many users without requiring powerful servers.

  • Cost-Effective: Eliminates the need for maintaining expensive servers.

20 of 122

Application-Layer Paradigms

Peer-to-Peer (P2P) Paradigm

Examples of P2P Applications

  • BitTorrent: Users share file pieces with each other until everyone has the full file.

  • Skype: Direct calls and messages between users, no central server needed.

  • Internet Telephony: Two users communicate like a phone call without a dedicated server.

  • IPTV: Video streaming and sharing happen without a central system.

21 of 122

Application-Layer Paradigms

Mixed Paradigm

  • Combines the advantages of Client-Server and Peer-to-Peer (P2P) paradigms.
  • Initially, a client-server interaction is used for light tasks like finding information.
  • Once the information is obtained, the actual service happens directly between peers using the P2P model.

Advantages

  • Reduces the load on servers by shifting heavy tasks to the P2P model.
  • Combines reliability of client-server for initial setup with scalability of P2P for actual data exchange.

22 of 122

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.

23 of 122

CLIENT-SERVER PROGRAMMING

  • In a client-server model, communication happens between two programs:

a client and a server.

  • The client initiates communication by sending a request, while the server waits for and responds to requests.

  • The server must always be running to handle client requests, but the client runs only when needed.

  • The server has an infinite lifetime, while the client has a finite lifetime, sending requests and receiving responses before stopping.

24 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API):

  • An API is a set of instructions for enabling communication between processes and the operating system.

  • APIs help the application layer communicate with the lower layers of the TCP/IP suite.

  • Common APIs for network communication include:
    • Socket Interface
    • Transport Layer Interface (TLI)
    • STREAM

25 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API):

  • The Socket Interface :
  • A socket interface is a programming way for processes to communicate over a network. It lets your program open a socket, send data, and receive data.
  • It acts like a door through which programs send and receive data.
  • Programs read and write data using network sockets instead of files or keyboards
  • Example: A web browser uses a socket to talk to a web server

26 of 122

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

27 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API): Sockets

  • A socket is an abstraction: it lets programs send and receive data over a network without dealing with the complex details of how the network works and used by the application program for communication.

Communication Between Processes:

  • At the application layer, communication between a client and a server occurs between two sockets, one at each end.
  • The client sees the socket as receiving the request and giving the response.
  • The server sees the socket as holding the request and needing a response.

28 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API): Sockets

Socket Creation:

  • By creating two sockets and defining the correct source and destination addresses, data can be sent and received using the available instructions.
  • The operating system and TCP/IP protocol manage the rest of the communication process.

29 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API): Socket Address

Two-Way Communication:

  • Client-server communication is bidirectional, requiring both a local (sender) and remote (receiver) address.
  • The local address in one direction is the remote address in the other direction, and vice versa.

Socket Addresses:

  • Communication occurs between two sockets, so we need two socket addresses: a local socket address and a remote socket address.

30 of 122

CLIENT-SERVER PROGRAMMING

Application Programming Interface (API): Socket Address

  • A socket address must identify the computer where the client or server is running, using an IP address (32-bit integer).
  • Since multiple processes can run on the same computer, a port number (16-bit integer) is also required to identify the specific client or server process.
  • Thus, a socket address combines the IP address and port number.

31 of 122

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:

  1. Local Socket Address:
    1. Provided by the operating system (OS), which knows the IP address of the server.
    2. The server's port number is either pre-assigned (for standard services like HTTP) or chosen by the server if custom.
  2. Remote Socket Address:
    • The server doesn’t know the client’s socket address beforehand.
    • It finds the remote address when a client attempts to connect, which is included in the client’s request packet.

32 of 122

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:

  1. Local Socket Address:
    1. Also provided by the OS, which knows the client’s IP address.
    2. A temporary port number is assigned each time a client starts communication, and it is guaranteed to be unique for that process.
  2. Remote Socket Address:
    • The client must know the server’s socket address before starting communication.
    • The server’s socket address can be provided directly (IP and port number) or obtained through a domain name (e.g., www.xxx.yyy), using the Domain Name System (DNS) to resolve the IP address.

33 of 122

CLIENT-SERVER PROGRAMMING

Using Services of the Transport Layer

UDP Protocol:

  • Service Type: Connectionless, unreliable, datagram service.
  • Communication: No logical connection between sending and receiving ends. Each message (datagram) is independent.
  • Reliability: Not reliable; no resending of lost or corrupted datagrams.
  • Usage: Suitable for applications needing speed and simplicity over reliability, like management and multimedia applications.

34 of 122

CLIENT-SERVER PROGRAMMING

Using Services of the Transport Layer

TCP Protocol:

  • Service Type: Connection-oriented, reliable, byte-stream service.
  • Communication: Establishes a logical connection via handshaking before sending data.
  • Reliability: Reliable; supports retransmission of lost or corrupted bytes.
  • Flow Control: Provides flow and congestion control.
  • Usage: Ideal for applications requiring reliability and long message transmission, such as file transfers.

35 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Client-Server Interaction:

  • Iterative Server: Processes one client request at a time. It receives a request, processes it, and sends a response before handling the next request.

  • Requests from other clients or the same client are queued and processed in a first-in, first-out (FIFO) order.

Client -> Request Datagram -> Server

Server -> Response Datagram -> Client

(if lost, client may resend)

36 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Sockets Used for UDP:

  • Server Socket: The server uses a single socket throughout its lifetime.

  • Client Socket: The client creates a socket that is closed when the client process terminates.

  • Each time a new client connects, the server updates the remote socket address, as it doesn’t know the client’s socket address beforehand. The server socket address remains fixed.

37 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Sockets Used for UDP:

38 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Flow Diagram : Server Process

  1. Passive Open: The server is ready to communicate but waits for client connections.
  2. Socket Creation: An empty socket is created and bound to the server’s IP address and a well-known port.
  3. Receive Request: The server issues a receive command, which blocks until a client sends a request.
  4. Socket Update: The server fills the socket with the client’s address upon receiving the request.

39 of 122

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.

40 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Flow Diagram : Client Process

  1. Active Open: The client starts the communication by creating an empty socket.
  2. Send Request: The client issues a send command to fill the socket(predefined or configured) and sends the request to the server.
  3. Receive Response: The client waits for a response from the server, blocking until the response arrives.
  4. Handle Response: The client processes the response and then closes (destroys) the socket.

41 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using UDP

Flow Diagram

42 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using TCP

Sockets Used in TCP: server uses two sockets

  1. Listen Socket: The server creates a listen socket for the connection establishment phase, where it waits for incoming client connection requests.
  2. Data Socket: After establishing a connection, the server creates a new socket for data exchange, used throughout the communication until the connection is terminated.
  3. Client Socket: The client uses a single socket for both connection establishment and data exchange.

Client -> SYN -> Server

Server -> SYN-ACK -> Client

Client -> ACK -> Server

Client -> Request -> Server

Server -> Response -> Client

43 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using TCP

Flow Diagram: Server Process

  1. Create and Bind Listen Socket: The server creates a listen socket and binds it, preparing for connection establishment.
  2. Listen: The server listens for incoming connection requests from clients and adds them to a waiting list.
  3. Accept Connection: The server accepts a client connection from the waiting list, creating a new socket for data transfer.
  4. Data Exchange: After the connection is established, the server and client can exchange data through the newly created socket.
  5. Handle Multiple Clients: The server serves each client one by one, handling the connection, data exchange, and termination in iterations.

44 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using TCP

Flow Diagram: Client Process

  1. Create Socket: The client creates a socket for both connection establishment and data exchange.
  2. Send Request: The client sends a connection request to the server.
  3. Receive Response: After the connection is established, the client sends and receives data as needed.
  4. Close Socket: Once communication is finished, the client closes the socket.

45 of 122

CLIENT-SERVER PROGRAMMING

Iterative Communication Using TCP

Flow Diagram

46 of 122

SOCKET INTERFACE PROGRAMMING

  • Socket programming is a way for two computers to communicate with each other over a network.
  • A socket acts like a virtual communication endpoint on both sides.
  • One side creates a server socket and waits.
  • The other side creates a client socket and connects.
  • After connection, they can send and receive data just like writing and reading from a file.

47 of 122

SOCKET INTERFACE PROGRAMMING

  • Computers need a way to talk to each other over a network.
  • Socket programming provides a standard, reliable method for this communication.
  • It allows building applications like:
    • Chat apps
    • Web servers
    • Email systems
    • File transfer systems
    • Games that work over the internet
  • It supports both TCP (reliable communication) and UDP (fast communication).

48 of 122

SOCKET INTERFACE PROGRAMMING

The echo program begins with socket programming, where:

  1. The server creates a socket�It binds to an IP and port.� It waits for a client to connect.
  2. The client creates a socket� It connects to the server using server’s IP and port.
  3. After the connection is established�The client sends a message.�The server receives it and sends the same message back (echo).
  4. Both sides must use recv() in a loop�Because TCP may deliver the message in parts.

49 of 122

SOCKET INTERFACE PROGRAMMING

Echo Client-Server Program

  • TCP does not guarantee that a full message sent by the client will arrive in one piece at the server.
  • The message may be broken into smaller segments during transmission.
  • Because of this, the server must call recv() inside a loop to collect the complete message.
  • The same situation happens when the server sends the echo reply.
  • The client may also receive the reply in multiple parts.
  • Therefore, the client must also use recv() repeatedly until the full echo message is received.

50 of 122

SOCKET INTERFACE PROGRAMMING

Echo Client-Server Program

Why do we use buffer variables?

  • When receiving data in parts, we must track:
  • ptr → where to put the next received chunk in the buffer
  • len → how many bytes received so far
  • maxLen → how many bytes still allowed in the buffer
  • Every time recv() returns some bytes:
    • ptr moves forward
    • len increases
    • maxLen decreases
  • This makes sure every new piece of data is stored in the right position.

51 of 122

SOCKET INTERFACE PROGRAMMING

52 of 122

SOCKET INTERFACE PROGRAMMING

Echo Client-Server Program

TCP Echo Server

  • Waits for clients
  • Accepts connection
  • Receives data (may come in pieces)
  • Sends the same data back
  • Closes connection

TCP Echo Client

Connects to server

Sends message

Receives echo message

Prints it

Closes connection

53 of 122

SOCKET INTERFACE PROGRAMMING

Concurrent Communication

  • A concurrent server can handle many clients at the same time.
  • It does not wait for one client to finish before serving the next.
  • This makes the server faster and more efficient.

How it works in different languages

    • In C:�The server creates child processes.�Each child process handles one client independently.

54 of 122

SOCKET INTERFACE PROGRAMMING

Concurrent Communication

How it works in different languages

    • In Java:�The server creates threads.�Each thread handles one client at a time, but many threads run together.

Why concurrency is useful

    • Multiple clients can be served simultaneously.
    • No client has to wait too long.
    • Overall performance and responsiveness of the server improve.

55 of 122

Standard Client-Server Protocols

  • Standard Client-Server Protocols are established rules that define how clients (user devices or applications) and servers (centralized systems or applications) communicate over a network.

  • These protocols ensure seamless data exchange, interoperability, and proper functioning of networked systems.

Standard Client Server Protocols: World Wide Web and HTTP, FTP, Electronic Mail, Domain Name System (DNS), TELNET, Secure Shell (SSH).

56 of 122

WORLD WIDE WEB

  • Proposed by Tim Berners-Lee in 1989 at CERN to enable researchers across Europe to access each other's work. Commercial Web started in the early 1990s .

  • Repository of Information: Acts as a vast collection of web pages distributed across the world, each containing text, images, or multimedia, all accessible through the internet.

  • Distribution: New web pages can be created and linked without affecting the performance of existing servers, allowing the web to grow continuously.

  • Linking: Hypertext links connect web pages globally, helping users easily navigate from one page or website to another.

57 of 122

WORLD WIDE WEB

  • Hypertext: Initially meant linked text documents; concept predates the Internet.
  • Hypermedia: Expanded to include text, images, audio, and video on web pages.
  • Beyond linked documents, the Web supports e-commerce, gaming, and on-demand media like radio and TV.

Architecture: Distributed client-server model: A client browser accesses services via servers located at multiple sites.

  • Web Pages:
    • Simple: No links to other pages.
    • Composite: Contains links to other pages.
    • Identified by a unique name and address.

58 of 122

WORLD WIDE WEB

Example 26.1

Files Involved:

    • File A: The main document.
    • File B: A large image stored on the same site as File A.
    • File C: A text file stored on a different site.

Transactions Needed:

    • Retrieve File A (the main document).
    • Click on the image reference in File A to retrieve File B.
    • Click on the text reference in File A to retrieve File C.

Independence of Files:

    • Each file (A, B, and C) is a separate web page with its own unique name and address.
    • Any file can be accessed individually through its respective transaction.

59 of 122

WORLD WIDE WEB

Web Client (Browser)

  1. Components:
    1. Controller: Handles input from keyboard/mouse, accesses documents, and displays them.
    2. Client Protocols: Examples include HTTP and FTP.
    3. Interpreters: Process document types like HTML, Java, or JavaScript.

  • Examples of Browsers:
    • Internet Explorer, Netscape Navigator, Firefox.

Web Server

  1. Function:
    1. Stores web pages and sends requested documents to clients.
  2. Efficiency Features:
    • Caching: Stores frequently requested files in memory for faster access.
    • Multithreading/Multiprocessing: Handles multiple requests simultaneously.

  • Examples of Servers:
    • Apache, Microsoft Internet Information Server.

60 of 122

WORLD WIDE WEB

Uniform Resource Locator (URL)

  • Uniquely identifies a web page using four components: protocol, host, port, and path.

Components:

  • Protocol: Specifies the client-server application, e.g., HTTP (default, port 80) or FTP.
  • Host: Server's IP address (e.g., 64.23.56.17) or domain name (e.g., forouzan.com).
  • Port: Predefined 16-bit number for the application (e.g., 80 for HTTP).
  • Path: Specifies the file's location on the server, e.g., /top/next/last/myfile.

Structure: Combines the four components with specific separators.

Example: http://www.mhhe.com/compsci/forouzan/

  • Protocol: http://
  • Host: www.mhhe.com
  • Path: compsci/forouzan/
  • Port: Not explicitly mentioned → uses default port for HTTP, which is 80.

61 of 122

WORLD WIDE WEB

Web Documents

Categories:

    • Static: Fixed content, created and stored on the server.
    • Dynamic: Generated by the server in response to a request.
    • Active: Executed at the client site for interaction or animation.

Static Documents:

  • Content is predefined and cannot be altered by the user.
  • Delivered as a copy to the client.
  • Commonly written in HTML, XML, XSL, or XHTML.

62 of 122

WORLD WIDE WEB

Web Documents

Dynamic Documents:

    • Created on-demand by the server.
    • May vary with each request (e.g., current time or date).

Common tools:

      • JSP (Java Server Pages)
      • ASP (Active Server Pages)
      • ColdFusion (SQL-embedded scripting).

Active Documents:

    • Require execution at the client side.
    • Examples: Animated graphics, user interaction programs.

Tools:

      • Java applets: Precompiled programs in bytecode format.
      • JavaScript: Scripts downloaded and executed by the client.

63 of 122

Hyper Text Transfer Protocol (HTTP)

  • It’s the standard protocol used for communication on the World Wide Web.
  • HTTP defines how messages are formatted and transmitted between a client and a server.
  • HTTP Client: Sends requests using temporary port numbers.
  • HTTP Server: Responds via port 80.
  • Uses TCP (connection-oriented and reliable) for error-free communication.

  • Connection Lifecycle:
  • Establish connection → Exchange data → Terminate connection.

64 of 122

Hyper Text Transfer Protocol

Nonpersistent vs. Persistent Connections

Nonpersistent Connections: A new TCP connection is created for each request-response cycle.

Steps:

    • Client opens a TCP connection and sends a request.
    • Server sends the response and closes the connection.
    • Client reads data until the end-of-file and closes the connection.

Overhead: For N linked objects on the same server:

    • The server must manage N + 1 connections.
    • This requires N + 1 buffers, which adds extra load to the server.
    • This wastes time, memory, and processing power

Browser connects → gets HTML → closes.�Then connects again → gets image1 → closes.�Repeats for image2, image3.

65 of 122

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.

  • The same connection is reused for all these objects.
  • This reduces overhead since it avoids opening and closing a new connection for each file.
  • The connection stays open for multiple requests and closes only after a timeout or when finished

Browser opens 1 connection → gets HTML + 3 images + 1 CSS file → then closes.

66 of 122

Hyper Text Transfer Protocol

Nonpersistent vs. Persistent Connections

Example 26.3: Nonpersistent Connection

  • A client retrieves a file and an image from the same server.

Steps:

    • First Connection: Establish connection → Request file → Transfer file → Close connection.
    • Second Connection:
      • Establish connection → Request image → Transfer image → Close connection.

Result:

    • 2 connections are needed.
    • Each connection has setup and teardown overhead (handshake delays).

67 of 122

Hyper Text Transfer Protocol

Nonpersistent vs. Persistent Connections

Example 26.4: Persistent Connection

  • The same file and image are retrieved using one connection.
  • Steps:
    • Establish connection.
    • Request file → Transfer file.
    • Request image → Transfer image.
    • Close connection.
  • Result:
    • Only 1 connection is used.
    • Saves time and resources by reducing handshake overhead.

68 of 122

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

69 of 122

Hyper Text Transfer Protocol

Request Message Format

  1. Body (Optional):

The body in an HTTP request is optional because not all requests need to send data to the server.

  • GET, HEAD, DELETE → Usually don’t need a body
  • POST, PUTRequire a body

70 of 122

Hyper Text Transfer Protocol

Response Message Format

  1. Status Line:
    • Version: The HTTP version used (e.g., HTTP/1.1).
    • Status Code: A three-digit code indicating the result of the request (e.g., 200 for success, 404 for not found).
    • Status Phrase: A short description of the status code (e.g., "OK" for 200, "Not Found" for 404).

  • Header Lines:
    • These lines provide additional information about the response, such as content type or server details.
    • Common headers include Content-Type, Date, Server, etc.

71 of 122

Hyper Text Transfer Protocol

Response Message Format

  1. Body:
    • Contains the content being sent from the server to the client (e.g., the requested document or error message).
    • The body is only included if the response is successful or contains content (e.g., not for a 404 error).

72 of 122

HyperText Transfer Protocol

HTTP Methods

  • GET: Requests a document from the server.
  • POST: Sends data to the server for processing.
  • PUT: Uploads a document to the server.
  • DELETE: Removes a document from the server.
  • HEAD: Requests only the header information of a document.
  • OPTIONS: Inquires about the available communication options.
  • TRACE: server sends back the exact request it received so developers can check or debug it.
  • CONNECT: Reserved for proxy servers(isn’t used by the client or origin server).
    • Proxy server is an intermediary between a client (like your browser) and the internet.

73 of 122

Hyper Text Transfer Protocol

Common Request Header Names

  • User-agent: Identifies the client program.
  • Accept: Specifies the media types the client can handle.
  • Authorization: Contains credentials for authentication.
  • Host: Specifies the server and port number being requested.
  • If-Modified-Since: Requests a document only if it has been modified since a specific date.

Common Response Header Names

  • Content-Type: Describes the type of content being returned (e.g., text/html, image/png).
  • Date: Indicates the date and time the response was sent.
  • Server: Specifies the software running on the server.
  • Location: Used in status code(301,302) responses to indicate the URL to redirect to.

  • 301: Redirect permanently.
  • 302: Found (temporary redirect).

74 of 122

Hyper Text Transfer Protocol

In HTTP, a client can make a conditional request by adding special headers.

  • The server returns the resource only if the condition is met.
  • If the condition isn’t met, the server tells the client instead of sending the resource.
  • A common example is checking if the resource has been modified since the last request.

Example: The client asks for /index.html

  • The If-Modified-Since header tells the server: “Send the file only if it was updated after Nov 6, 2024.”

Server’s Response

  • 200 OK → if the file was modified after that date (sends the file).
  • 304 Not Modified → if the file hasn’t changed (no data sent, saves bandwidth)

Conditional request

75 of 122

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

76 of 122

Hyper Text Transfer Protocol

Web Caching: Proxy Servers

  • Web Caching is a way to temporarily store web content (like pages, images, videos) closer to users to make loading faster.

  • Proxy server caching: A proxy server gets responses from the original server the first time a client requests a resource. It stores (caches) that response locally, for future requests,

  • The proxy acts as both a client and a server depending on the request.

77 of 122

Hyper Text Transfer Protocol

Web Caching: Proxy Servers

Functionality:

  1. Request Handling:
    1. If the requested data exists in the proxy's cache, it acts as a server and responds to the client.
    2. If the data is unavailable, the proxy acts as a client, forwarding the request to the target server.
  2. Response Handling:
    • The proxy server stores incoming responses in its cache for future requests.
    • It then forwards the response to the client.

78 of 122

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.

79 of 122

File Transfer Protocol (FTP)

FTP Components:

  • Client Side:
    • User Interface: For interacting with users.
    • Client Control Process: Manages control commands.
    • Client Data Transfer Process: Handles the transfer of data.

  • Server Side:
    • Server Control Process: Responds to client commands.
    • Server Data Transfer Process: Facilitates data transmission.

80 of 122

File Transfer Protocol (FTP)

Control Connection:

  • It handles commands and responses between client and server.
  • Uses simple line-by-line communication (one command or response per line).
  • Stays open for the entire FTP session to manage transfers and session control.

81 of 122

File Transfer Protocol (FTP)

Data Connection:

  • It transfers the actual files between client and server.
  • Handles different data types like text or binary.
  • Opens a separate connection for each file transfer and closes it afterward.
  • Uses different ports depending on FTP mode (active or passive).

82 of 122

File Transfer Protocol (FTP)

83 of 122

ELECTRONIC MAIL

  • Electronic mail (e-mail) differs from other applications like HTTP or FTP, where a server waits for client requests.
  • In e-mail, the transaction is typically one-way, with the sender expecting, but not necessarily receiving, a response.
  • Servers in e-mail systems are intermediate, as users do not need to keep their computers running all the time.

84 of 122

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:

  1. User Agent (UA): This software allows users to compose, read, reply to, and manage e-mails. It interacts with the local mailbox.

  • Message Transfer Agent (MTA): This agent is responsible for transferring messages between servers. There are two types: client-side MTA and server-side MTA. The client-side MTA pushes messages to the server, and the server-side MTA waits for messages and stores them.

85 of 122

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.

86 of 122

ELECTRONIC MAIL

E-mail scenario:

Storage area where outgoing messages are stored

Storage area where incoming messages are stored

87 of 122

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:

  1. Command-driven UAs: Early email systems using keyboard commands (e.g., mail, pine).
  2. GUI-based UAs: Modern email clients with graphical interfaces (e.g., Eudora, Outlook).

Sending Mail:

The email consists of:

  • Envelope: Contains sender and recipient addresses.
  • Message: Includes a header (sender, recipient, subject) and the body (content).

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.

88 of 122

ELECTRONIC MAIL - Format of an e-mail

Addresses: An email address has two parts:

  • Local Part: User's mailbox.
  • Domain Name: Mail server handling the email.

Mailing List: When you send an email to the mailing list, everyone in the list gets their own copy.

89 of 122

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).

  • SMTP (Simple Mail Transfer Protocol) is used between the sender's mail server and the recipient's mail server. It defines the commands and responses exchanged between the MTA client and MTA server. SMTP is used twice: first, between the sender and their mail server, and second, between the two mail servers.

90 of 122

ELECTRONIC MAIL

SMTP command and responses

91 of 122

ELECTRONIC MAIL

Commands and Responses

  • SMTP commands are sent from the client to the server to initiate actions like sending mail or specifying recipients.
  • Responses, consisting of a three-digit code and optional text, are sent from the server to indicate the status of each command.

92 of 122

ELECTRONIC MAIL - Mail Transfer Phases

The mail transfer process occurs in three phases:

1. Connection Establishment

    • Client → Server: request done with port number 25
    • Server → Client:220 – Server says “I am ready.”
    • Client → Server:HELO or EHLO – Client identifies itself.
    • Server → Client:250 – Server acknowledges the client.

93 of 122

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

  1. MAIL FROM: sender’s email�→ Server replies 250 OK
  2. RCPT TO: receiver’s email�→ Server replies 250 OK
  3. DATA → Server replies 354 Start mail input

3. Connection Termination

  • Client → Server: QUIT
  • Server → Client: 221 Goodbye

94 of 122

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.

  1. POP3: Downloads email from server and deletes from server

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.

  • IMAP4: Keeps email on the server allowing others to access

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.

95 of 122

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:

  1. MIME-Version: Indicates the MIME version used, with the current version being 1.1.
  2. Content-Type: Specifies the type and subtype of data in the email body (e.g., text/plain, image/jpeg), with additional parameters depending on the subtype.

NVT is a standard way of sending characters

96 of 122

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.

97 of 122

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),

98 of 122

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:

  • Helps understand remote logging
  • Used by network admins for diagnostics and debugging.

99 of 122

TELNET

Local vs Remote Logging:

  • Local Logging: User interacts directly with the local operating system.
  • Remote Logging: User connects to a remote machine using TELNET.

100 of 122

TELNET

Network Virtual Terminal (NVT) : NVT acts as a translator between different computer systems.

  • It ensures communication between systems even if they use different character set(data like text). or commands.

  1. At the Client Side:
    1. Your keyboard inputs (characters or commands) are converted into a standard format called NVT form.
    2. This ensures the message is understandable by any system.
  2. At the Server Side:
    • The NVT form is converted back into the format the remote system understands.

101 of 122

TELNET

Network Virtual Terminal (NVT) :

Options and User Interface:

  • Options:
    • TELNET lets you choose features based on the terminal's capability.
    • Basic terminals use defaults, while advanced ones can enable extra features.
  • Commands:
    • Operating systems like UNIX provide simple commands to use TELNET.

Concept of NVT

102 of 122

SECURE SHELL (SSH)

SSH is a secure application-layer protocol originally designed to offer enhanced security and versatility.

  1. SSH Transport-Layer Protocol (SSH-TRANS): This protocol establishes a secure channel over TCP by providing:

  • Privacy (Confidentiality): Ensures messages are encrypted.
  • Data Integrity: Guarantees messages remain unaltered during transmission.
  • Server Authentication: Confirms the server’s identity to the client.
  • Compression: Improves efficiency and makes attacks harder.

103 of 122

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.

  • Each channel can serve a different purpose, such as:
    • Remote logging.
    • File transfers.
    • Other communication tasks.

104 of 122

SECURE SHELL (SSH)

Applications of SSH:

  1. Remote Logging:
    • A secure method to access and manage remote systems, using encrypted connections provided by SSH.

2. File Transfer:

  • SSH tunnels ensure secure file transfers using applications like:
    • Secure File Transfer Program (sftp): Transfers files securely over SSH.
    • Secure Copy (scp): Mimics the UNIX cp command for secure copying.

  1. Port Forwarding (SSH Tunneling):
    • SSH Creates a tunnel, to protect the communication like SMPTP, FTP.

105 of 122

SECURE SHELL (SSH)

Format of SSH Packets:

    • Length Field: Specifies the packet length, excluding padding.
    • Padding: 1-8 byte added for enhanced security against attacks (extra random bytes to the end of each encrypted packet).
    • Cyclic Redundancy Check (CRC): Ensures error detection.
    • Type Field: Indicates the type of SSH packet for various protocols(error message, authentication message, connection message).
    • Data Field: Contains the actual data being transmitted in the protocol.

106 of 122

Domain Name System (DNS)

  • DNS maps human-friendly domain names (e.g., example.com) to IP addresses used by machines for communication.

  • Distributed System: DNS uses a distributed hierarchy of servers to ensure efficiency and reliability(translate human-readable domain names (like www.example.com) into machine-readable IP addresses (like 192.168.1.1).

107 of 122

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.

  • It is designed as an inverted tree with the following characteristics:

    • Root server tells which TLD server to contact (like .com or .in).
    • TLD(Top-Level Domain) server tells which authoritative server handles that domain.
    • Authoritative server gives the actual IP address of the website.

108 of 122

Domain Name System (DNS)

Domain Name Space:

Levels:

      • DNS can have up to 128 levels (numbered 0 to 127).
      • Each part (label) of a domain name is one level.

Example: In www.example.com:

        • Level 1: .com (Top-Level Domain, TLD).
        • Level 2: example (Second-Level Domain).
        • Level 3: www (Subdomain).

109 of 122

Domain Name System (DNS)

Domain Name Space:

DNS Levels: Example

a.b.c.d.e.school.university.example.com

from right to left:

  1. com → Top-Level Domain (TLD)
  2. example → Second-Level Domain (SLD)
  3. university → Subdomain
  4. school → Subdomain
  5. e → Subdomain
  6. d → Subdomain
  7. c → Subdomain
  8. b → Subdomain
  9. a → Subdomain (deepest level)

In this domain, there are 9 nodes/levels.

(root)

|

com

|

example

|

university

|

school

|

e

|

d

|

c

|

b

|

a

110 of 122

Domain Name System (DNS)

Domain Name Space

  • A domain name is made up of small parts called labels.
  • Each label is like a node in the DNS hierarchy.
  • Example: mail.google.com.

mail → one node

google → another node

com → another node

  • These nodes form a hierarchy that helps the internet find websites easily.

111 of 122

Domain Name System (DNS)

  • Domain Name Space:

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.

112 of 122

Domain Name System (DNS)

  • Domain Name Space:

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

113 of 122

Domain Name System (DNS)

A domain includes the main name and all its subdomains.

For example, the domain example.com includes:

  • www.example.com
  • mail.example.com
  • shop.example.com
  • api.shop.example.com, etc.

So, a domain = full subtree under example.com.

Domain and Zone

114 of 122

Domain Name System (DNS)

Zone

A zone is the portion of the domain that a DNS server is responsible for.

Example:

  • www.example.com can be one zone (managed by one DNS server)
  • mail.example.com can be another zone (managed by another DNS server)

Even though they all belong to the same domain (example.com),�they can be split into multiple zones for management.

Domain and Zone

115 of 122

Domain Name System (DNS)

Domain and Zone

Domain Names

  1. edu.
  2. topUniversity.edu.
  3. bDept.topUniversity.edu.
  4. aComputer.bDept.topUniversity.edu.

Zones

1. edu. zone

  • Managed by a DNS server for the edu top-level domain.

2. topUniversity.edu. zone

  • Managed by the DNS server for topUniversity.

3. bDept.topUniversity.edu. zone

  • Managed by the DNS server for the bDept department.

  • aComputer.bDept.topUniversity.edu. → This is not a zone, just a host record inside the bDept zone.

116 of 122

Domain Name System (DNS)

Resolution in DNS:

    • Name-address resolution is the process of converting a domain name into an IP address.
    • In DNS, a client (resolver) asks a server for the address. A resolver is a DNS client program that sends DNS queries on behalf of your computer.
    • If the server has it, it provides the answer; if not, it directs the client to another server. This can be done recursively (server handles all queries) or iteratively (client queries multiple servers).

1. Recursive Resolution:

    • In recursive resolution, the resolver sends a query to a DNS server. If that server doesn't have the information, it queries other servers on behalf of the resolver.

117 of 122

Domain Name System (DNS)

Resolution in DNS:

2. Iterative Resolution:

  • In iterative resolution, each server that doesn’t know the mapping sends the IP address of the next server back to the resolver, instead of making further queries on behalf of the client.

Recursive Resolution Iterative Resolution

118 of 122

Domain Name System (DNS)

Caching in DNS:

  • When a DNS server gets an answer (like google.com → IP), it saves it in its cache to answer future queries faster.
  • Every saved entry has a TTL (Time to Live), which tells how many seconds it can stay in the cache.
  • The server keeps checking the TTL.�When the TTL becomes zero, the entry is removed, and the server must ask again from the authoritative server to get fresh, updated information.

119 of 122

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:

  1. Time to Live (TTL):
    1. Each mapping stored in the cache comes with a TTL value, which is the duration (in seconds) that the server can cache the information.
    2. Once the TTL expires, the mapping is considered invalid, and a new query must be sent to the authoritative server for updated information.

  • TTL Counter:
    • Each DNS server maintains a TTL counter for every mapping it caches.
    • Servers periodically check the TTL values of the cached mappings. If the TTL has expired, the mapping is eliminated from the cache to ensure only valid data is used for future queries.

120 of 122

Domain Name System (DNS)

DNS Message Format

  1. Identification Field: Helps the client match the response with the query.
  2. Flag Field: Indicates whether the message is a query or response and shows any errors.
  3. Record Count Fields: Define the number of each type of record in the message(what kind of information a DNS record contains).
  4. Question Section: Contains the query being asked, present in both query and response messages.
  5. Answer Section: Contains the answer to the query, present only in response messages.
  6. Authoritative Section: Provides information about authoritative servers for the query.
  7. Additional Information Section: Provides extra data that may help in resolving the query.

121 of 122

Domain Name System (DNS)

DNS Message Format

122 of 122

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:

  1. Eavesdropping: Attackers can monitor DNS responses to gather information about a user's preferences.
  2. Response Tampering: Attackers might change DNS responses to redirect users to fake websites.
  3. DoS Attacks: Attackers can overload DNS servers, causing them to crash.