COMPUTER NETWORKS
5 SEM – AI&ML
th
2025
Pradeep Shetty
COMPUTER NETWORKS
Course Objectives:
1. Demonstration of application layer protocols
2. Discuss transport layer services and understand UDP and TCP
protocols
3. Explain routers, IP and Routing Algorithms in network layer
4. Disseminate the Wireless and Mobile Networks covering IEEE
802.11 Standard
5. Illustrate concepts of Multimedia Networking, Security and
Network Management.
Course Outcomes:
After studying this course, students will be able to:
CO-1: Understand the fundamental concepts of computer networks by explaining
network architectures, protocols, and communication models.
CO-2: Apply computer networking principles to design, configure, and
troubleshoot network setups, showcasing practical skills in network
configuration and troubleshooting.
CO-3: Critically assess and optimize computer networks by analyzing network
performance,security measures, and scalability considerations to ensure
efficient and reliable data communication.
MODULE 1 (9 Hours)
Application Layer: Principles of Network Applications: Network Application
Architectures, Processes Communicating, Transport Services Available to Applications,
Transport Services Provided by the Internet, Application-Layer Protocols. The Web and
HTTP: Overview of HTTP,
Non-persistent and Persistent Connections, HTTP Message Format, User-Server
Interaction:
Cookies, Web Caching, The Conditional GET, File Transfer: FTP Commands & Replies,
Electronic Mail in the Internet: SMTP, Comparison with HTTP, Mail Message Format, Mail
Access Protocols
Socket Programming: creating Network Applications: Socket Programming with UDP,
Socket Programming with TCP.
MODULE 2 (9 Hours)
Transport Layer : Introduction and Transport-Layer Services: Relationship Between
Transport
and Network Layers, Overview of the Transport Layer in the Internet, Multiplexing and
Demultiplexing: Connectionless Transport: UDP,UDP Segment Structure, UDP
Checksum,
Principles of Reliable Data Transfer: Building a Reliable Data Transfer Protocol, Pipelined
Reliable Data Transfer Protocols, Go-Back-N, Selective repeat, Connection-Oriented
Transport
71
TCP: The TCP Connection, TCP Segment Structure, Round-Trip Time Estimation and
Timeout,
Reliable Data Transfer, Flow Control, TCP Connection Management.
MODULE 3 (9 Hours)
The Network layer: What's Inside a Router?: Input Processing,
Switching, Output Processing,
Where Does Queuing Occur? Routing control plane, IPv6,A Brief
foray into IP Security, Routing
Algorithms: The Link-State (LS) Routing Algorithm, The Distance-
Vector (DV) Routing
Algorithm, Hierarchical Routing, Routing in the Internet, Intra-AS
Routing in the Internet:
RIP,OSPF, Inter/AS Routing: BGP, Broadcast and Multicast Routing.
MODULE 4 (9 Hours)
Wireless and Mobile Networks: Cellular Internet Access: An Overview of
Cellular Network
Architecture, 3G Cellular Data Networks: Extending the Internet to Cellular
subscribers, On to
4G:LTE,Mobility management: Principles, Addressing, Routing to a mobile
node, Mobile IP,
Managing mobility in cellular Networks, Routing calls to a Mobile user,
Handoffs in GSM,
Wireless and Mobility: Impact on Higher-layer protocols.
MODULE 5 (9 Hours)
Multimedia Networking: Properties of video, properties of
Audio, Types of multimedia Network Applications
Streaming stored video: UDP Streaming, HTTP Streaming,
Case studies: Netflix, You Tube and Kankan.
Network Support for Multimedia: Dimensioning Best-
Effort Networks, Providing Multiple Classes of Service.
MODULE 1 (9 Hours)
1. Application Layer: Principles of Network Applications: Network Application Architectures,
2. Processes Communicating, Transport Services Available to Applications,
3. Transport Services Provided by the Internet,
4. Application-Layer Protocols. The Web and HTTP: Overview of HTTP,
5. Non-persistent and Persistent Connections, HTTP Message Format, User-Server Interaction:
6. Cookies, Web Caching, The Conditional GET, File Transfer: FTP Commands & Replies, Electronic
7. Mail in the Internet: SMTP, Comparison with HTTP, Mail Message Format, Mail Access Protocols
8. Socket Programming: creating Network Applications: Socket Programming with UDP, Socket
9. Programming with TCP.
Application Layer: Principles of Network Applications & Architecture
The application layer in computer networks is the highest
layer in the TCP/IP and OSI models.
It provides the interface between applications and the
network, enabling them to communicate and exchange
data.
Understanding the principles of network applications
involves looking at various aspects, including their
architecture, how processes communicate, the protocols
they use, and the services they require from the
underlying layers.
1. Network Application Architectures:
Client-Server Architecture: This is a predominant model where an "always-on" host (the
server) provides services to many other hosts (clients) that request those services.
Clients do not directly communicate with each other. Examples include web applications
(browsers as clients, web servers as servers), email, and FTP. Servers often reside in data
centers.
Peer-to-Peer (P2P) Architecture: In this model, there's minimal or no reliance on
dedicated servers. Instead, the application exploits direct communication between
intermittently connected hosts (peers). Each peer can act as both a client and a server,
providing and requesting resources. P2P systems are often self-scalable, as new peers
add both workload and service capacity. Examples include BitTorrent, Skype (for direct
calls), and many online gaming systems.
Hybrid Architectures: Many modern applications combine elements of both client-
server and P2P, leveraging the strengths of each. For instance, instant messaging
applications might use a central server for presence detection and user location, but
direct P2P connections for actual chat between users.
2. Process Communication:
Processes, not Programs: In networking, it's not entire programs that communicate, but
rather processes (instances of running programs) on different end systems.
Client and Server Processes: Within a communication session, the process that
initiates the communication is typically labeled the "client process," and the process that
waits to be contacted is the "server process." Even in P2P architectures, at any given
moment, one peer acts as a client and the other as a server for a specific interaction.
Messages: Processes communicate by exchanging messages over the network. A
sending process creates and sends messages, and a receiving process receives and
potentially responds to them.
Sockets: A socket is a software interface between the application layer and the transport
layer within a host. It's the "door" through which processes send and receive messages to
and from the network. Application developers primarily interact with the network through
this socket API.
3. Application-Layer Protocols:
Defining Communication Rules: An application-layer protocol defines how an
application's processes, running on different end systems, exchange messages. This
includes:
Types of messages: E.g., request messages, response messages.
Syntax: The structure and format of messages (fields, delimiters).
Semantics: The meaning of the information contained within the message fields.
Rules: When and how processes send messages and respond to them.
Open vs. Proprietary Protocols:
Open protocols: These are publicly specified, often in RFCs (Request for
Comments), allowing different developers and organizations to build interoperable
applications (e.g., HTTP, SMTP, FTP, DNS).
Proprietary protocols: These are privately controlled and used by specific
companies or applications (e.g., some early VoIP protocols).
4. Services Required from Transport Layer:
Network applications have varying service requirements, and they rely on the
underlying transport layer protocols (primarily TCP and UDP) to provide these.
Key service requirements include:
Data Loss:
Reliable Data Transfer (No Loss): Some applications, like file transfer
(FTP), email (SMTP), and web Browse (HTTP), require 100% reliable data
transfer. Loss of even a single byte can be catastrophic. TCP provides
this reliability.
Loss-Tolerant Applications: Other applications, particularly multimedia
streaming (audio/video), can tolerate some data loss without significant
degradation in quality. For these, speed is often more critical than
absolute reliability. UDP is often preferred here.
Throughput (Bandwidth):
o Bandwidth-Sensitive Applications: Some applications (e.g., Internet telephony) require a minimum
amount of throughput to be effective. If the required bandwidth isn't available, the application might not
function properly.
o Elastic Applications: Many applications (e.g., email, file transfer, web Browse) can make use of as
much or as little bandwidth as available. More bandwidth generally leads to better performance, but
there isn't a strict minimum.
Timing:
o Time-Sensitive Applications: Interactive real-time applications like video conferencing, online gaming,
and Internet telephony require low end-to-end delays for effective interaction. Delays of more than a
few hundred milliseconds can significantly impair usability.
Security:
o Applications often need security services like encryption, data integrity, and authentication. While the
transport layer (e.g., SSL/TLS built on top of TCP) or even the application layer itself can provide these,
it's a critical consideration for many network applications.
Core Application Layer Protocols & Their Examples:
1. HTTP (Hypertext Transfer Protocol)
Purpose: The foundation of the World Wide Web. Used for fetching web pages, images, videos, and
other resources from web servers.
Applications:
Web Browsers (Chrome, Firefox, Safari, Edge): These are the primary clients that send HTTP
requests to web servers.
Web Servers (Apache, Nginx, IIS): These are the servers that host websites and respond to HTTP
requests.
RESTful APIs: Many modern web services and mobile apps use HTTP as the transport for their API
calls (e.g., fetching data for a weather app, submitting an online order).
Web Scrapers/Crawlers: Programs that automatically navigate and extract data from websites
using HTTP.
Key Principle Illustrated: Client-Server architecture, Request-Response message exchange.
2. HTTPS (Hypertext Transfer Protocol Secure)
o Purpose: HTTP with an added layer of security (encryption, authentication) provided
by SSL/TLS. Essential for secure online transactions and private Browse.
o Applications:
Online Banking Websites: When you log into your bank, the connection is always
HTTPS to protect your credentials and financial data.
E-commerce Sites (Amazon, Flipkart): All purchases and login pages use HTTPS
to secure credit card details and personal information.
Social Media Platforms (Facebook, Instagram): HTTPS encrypts your posts,
messages, and login details.
o Key Principle Illustrated: Security requirement from the transport layer (TLS over
TCP), Client-Server architecture.
3. FTP (File Transfer Protocol)
Purpose: For transferring files between a client and a server. It
uses separate control and data connections.
Applications:
FileZilla, WinSCP, Cyberduck: Dedicated FTP client
software used by web developers to upload website files to
web servers, or by users to download large files from FTP
servers.
Web Hosting Services: Often provide FTP access for users
to manage their website files.
Key Principle Illustrated: Client-Server architecture, Reliable
data transfer (uses TCP).
4. SMTP (Simple Mail Transfer Protocol)
o Purpose: Used for sending emails from an email client to a mail server, and for
transferring emails between mail servers.
o Applications:
Email Clients (Outlook, Thunderbird, Apple Mail): When you click "Send," your
client uses SMTP to push the email to your outgoing mail server.
Mail Servers (Postfix, Sendmail, Exchange Server): These servers use SMTP to
relay emails to other mail servers.
Webmail Services (Gmail, Yahoo Mail): While you interact via HTTP in your
browser, the underlying sending mechanism for these services still uses SMTP.
o Key Principle Illustrated: Client-Server architecture, Reliable data transfer (uses
TCP).
5. POP3 (Post Office Protocol version 3) / IMAP (Internet Message Access Protocol)
o Purpose: Both are used by email clients to retrieve emails from a mail server.
POP3: Generally downloads emails to the local device and often deletes them from
the server (though configurable).
IMAP: Keeps emails on the server, allowing synchronization across multiple
devices.
o Applications:
Email Clients (Outlook, Thunderbird, Apple Mail): These clients connect to your
incoming mail server using POP3 or IMAP to download/synchronize your inbox.
Mobile Email Apps: Almost exclusively use IMAP for seamless synchronization.
o Key Principle Illustrated: Client-Server architecture, Reliable data transfer (uses
TCP).
6. DNS (Domain Name System)
Purpose: Translates human-readable domain names (e.g., www.google.com) into
machine-readable IP addresses (e.g., 142.250.190.4). It's crucial for virtually all
internet activity.
Applications:
Web Browsers: Before your browser can send an HTTP request to
www.example.com, it first performs a DNS lookup to find the IP address of
www.example.com.
Email Clients: Before sending an email to
[email protected], the client or
server performs a DNS lookup to find the mail server's IP address for
example.com.
Operating Systems: Almost all operating systems have a built-in DNS client that
handles these lookups transparently.
Key Principle Illustrated: Critical supporting service for almost all other
applications, often uses UDP for quick lookups (but TCP for zone transfers).
7. SSH (Secure Shell)
Purpose: Provides a secure channel over an unsecured network for remote
command-line login, remote command execution, and secure file transfer (SFTP).
Applications:
Terminal Emulators ( OpenSSH client): System administrators and developers
use SSH to securely connect to remote servers to manage them.
SCP (Secure Copy Protocol) / SFTP (SSH File Transfer Protocol): Built on SSH
for secure file transfer.
Version Control Systems (Git): Often use SSH for secure communication with
remote repositories.
Key Principle Illustrated: Client-Server architecture, Strong security features
(encryption, authentication).
8. Telnet (Telecommunication Network)
Purpose: An older, unencrypted protocol for remote
command-line access. Largely replaced by SSH due to
security concerns.
Applications:
Legacy Systems: Still found in some very old network
devices or systems that don't support SSH.
Key Principle Illustrated: Client-Server architecture
(but lacks security).
9. DHCP (Dynamic Host Configuration Protocol)
Purpose: Automatically assigns IP addresses and other network
configuration parameters (like DNS server addresses, default gateway)
to devices on a network.
Applications:
Routers (acting as DHCP servers): Your home router is typically a
DHCP server, assigning IP addresses to your phone, laptop, smart TV,
etc., when they connect to your Wi-Fi.
Operating Systems (DHCP clients): Your computer's operating
system has a DHCP client that requests an IP address when it
connects to a network.
Key Principle Illustrated: Client-Server architecture, essential network
support service.
10. RTP (Real-time Transport Protocol) / RTCP (RTP Control Protocol)
Purpose: Used for delivering real-time multimedia (audio and video) over
IP networks. RTP handles the data stream, while RTCP provides control
information (feedback on quality, synchronization).
Applications:
VoIP (Voice over IP) applications (Zoom, Google Meet, Microsoft
Teams): These applications use RTP to stream the voice and video data
during a call.
Live Streaming Services: While HTTP is used for many on-demand
streams, live, low-latency streaming often employs RTP.
Key Principle Illustrated: Designed for time-sensitive and loss-tolerant
applications (often runs over UDP), specifically addresses timing and
throughput requirements.
Transport Services Available to Applications
The transport layer sits between the application layer and the network
layer.
Its main responsibility is to provide logical communication between
application processes running on different hosts. Key services include:
1.Process-to-Process Communication (Port Addressing):
1.The network layer delivers data between hosts, but the transport
layer goes a step further by delivering data to specific applications
(processes) running on those hosts.
2.This is achieved through port numbers. Each application that wants
to receive data registers with a unique port number. The transport
layer uses these port numbers to direct incoming data to the correct
application.
2 Multiplexing and Demultiplexing:
Multiplexing (at the sender): The transport layer at the
sending host collects data from various application
processes, adds headers (including port numbers), and
passes it down to the network layer as a single stream of
segments. This allows multiple applications to share the
same network connection.
Demultiplexing (at the receiver): The transport layer at
the receiving host receives segments from the network
layer, uses the port numbers in the header to identify the
target application, and delivers the data to the correct
process.
3 Error Control/Detection and Correction:
Ensures that data arrives at the destination without
corruption, loss, or duplication.
Mechanisms like checksums are used to detect errors. If
errors are detected or segments are lost, retransmission
mechanisms are employed to ensure reliable delivery.
4 Flow Control:
Prevents a fast sender from overwhelming a slow
receiver.
The receiver signals to the sender how much data it can
handle, preventing buffer overflow and subsequent
packet loss.
5 Congestion Control:
Manages the flow of data when the network itself is
overloaded (congested).
This prevents network collapse by regulating the
sending rate of applications to match the network's
capacity.
6 Connection Management (for connection-oriented
services):
Establishes, maintains, and terminates a logical
connection between two application processes before
data transfer begins. This involves a "handshake"
process.
Transport Services Provided by the Internet (via TCP and UDP)
The Internet primarily offers two transport protocols, TCP and UDP,
each providing a different set of services:
1. TCP (Transmission Control Protocol)
TCP is a connection-oriented and reliable protocol, making it
suitable for applications where data integrity and order are
paramount.
Services provided by TCP:
Connection-Oriented Service: Before data can be exchanged,
TCP establishes a virtual connection (a "handshake") between the
sending and receiving applications.
o This connection is full-duplex, allowing simultaneous
communication in both directions. The connection is terminated
when data transfer is complete.
Reliable Data Transfer:
Error Detection and Correction: Uses checksums to detect corrupted segments
and mechanisms like acknowledgments (ACKs) and retransmissions to recover lost
or corrupted data.
In-Order Delivery: Guarantees that data segments are delivered to the application in
the same order they were sent, even if they arrive out of order at the network layer.
This is achieved through sequence numbers.
No Duplication: Ensures that the receiving application receives each byte of data
exactly once.
Flow Control:
Prevents the sender from overwhelming the receiver's buffer by regulating the sending
rate based on the receiver's advertised window size.
Congestion Control: TCP dynamically adjusts the sending rate based on network
congestion, helping to p revent and alleviate network overload. It uses mechanisms like
"slow start" and "congestion avoidance."
Byte Stream Service: TCP treats data as a continuous stream of bytes, not discrete
messages. The application writes bytes to a TCP socket, and TCP handles the
segmentation and reassembly.
Applications that use TCP:
Web Browse (HTTP/HTTPS): Requires reliable transfer of
web pages, images, and other content.
Email (SMTP, POP3, IMAP): Essential for ensuring emails
are delivered completely and without errors.
File Transfer (FTP): Guarantees that files are transferred
intact.
Remote Login (SSH, Telnet): Requires reliable, in-order
delivery of commands and responses.
2. UDP (User Datagram Protocol)
UDP is a connectionless and unreliable protocol. It offers a "best-effort"
delivery service, meaning it sends data without guarantees of delivery, order, or
error-free transmission.
Services provided by UDP:
Connectionless Service: UDP does not establish a connection before
sending data. Each UDP datagram is treated independently.
Minimal Overhead: Due to its lack of reliability and connection
management features, UDP has very low overhead, making it faster than
TCP.
Process-to-Process Communication (Port Addressing): Like TCP, UDP
uses port numbers to deliver datagrams to specific applications.
Checksum (Optional): While it includes a checksum for error detection, it
doesn't guarantee retransmission if an error is found.
Applications that use UDP:
Real-time Multimedia Applications (Voice over IP - VoIP, Video
Conferencing): These applications can tolerate some data loss but
are highly sensitive to delay. Retransmitting lost packets would
introduce unacceptable delays.
Online Gaming: Speed is crucial; minor packet loss is often less
disruptive than retransmission delays.
Domain Name System (DNS): Quick query-response operations,
where reliability can be handled at a higher layer or by trying again if
a response is not received.
SNMP (Simple Network Management Protocol): Used for
network device management where individual messages are often
small and occasional loss is acceptable.
Summary of Protocols
𝗧𝗖𝗣/𝗜𝗣 – The backbone of the internet! TCP ensures data is split into packets and delivered correctly, while IP
handles addressing and routing. Without them, the internet wouldn't work as we know it.
𝗗𝗡𝗦 – Think of this as the internet’s phonebook. It translates domain names (like 𝚐𝚘𝚘𝚐𝚕𝚎.𝚌𝚘𝚖) into IP
addresses, so computers know where to connect.
𝗛𝗧𝗧𝗣 – This protocol helps websites communicate with your browser. It defines how web pages, images, and
other content are transferred.
𝗛𝗧𝗧𝗣𝗦 – The secure version of HTTP. It encrypts data to ensure safe browsing and protect sensitive
information.
𝗦𝗠𝗧𝗣 – The email postman! It handles sending emails from one server to another, ensuring messages reach
the right inbox.
𝗙𝗧𝗣 – A file transfer service that helps move files between computers and servers, whether you’re uploading or
downloading.
𝗨𝗗𝗣 – For speed! Unlike TCP, UDP doesn’t check if packets arrive in perfect order, making it ideal for live
streaming, gaming, and real-time communications.
The Web and HTTP: Overview of HTTP,
Non-persistent and Persistent Connections, HTTP Message Format
The Web and HTTP: An Overview
The World Wide Web (WWW) is a vast system of
interconnected documents and other web resources,
identified by URLs (Uniform Resource Locators), which
may be interlinked by hyperlinks, and are accessible
via the Internet. HTTP is the primary protocol used to
access these resources.
What is HTTP?
HTTP is an application-layer protocol for distributed, collaborative, hypermedia
information systems. It's the protocol used by web browsers (clients) to request web
pages and other resources from web servers, and by web servers to deliver those
resources.
Key Characteristics of HTTP:
Client-Server Model: HTTP operates on a client-server model. A web browser acts as
the client, initiating requests to a web server, which then responds with the requested
resources.
Stateless Protocol: HTTP is inherently stateless. This means that each request from a
client to a server is treated as an independent transaction. The server does not retain
any memory or information about past client requests. While this simplifies server
design, it requires mechanisms (like cookies) for maintaining session state in web
applications.
Request/Response Paradigm: Communication in HTTP follows a request/response
paradigm. The client sends an HTTP request, and the server sends an HTTP response.
Text-Based: HTTP messages are typically human-readable, consisting of lines of text.
Non-Persistent and Persistent Connections
When a client wants to retrieve an object from a web server, it establishes a TCP connection. How this TCP
connection is used for subsequent object retrievals leads to two types of connections:
1. Non-Persistent Connections
Mechanism: With non-persistent connections, a separate TCP connection is established for each
requested object. After the server sends an object, the TCP connection is closed.
Steps:
Client initiates a TCP connection to the server on port 80 (for HTTP).
Client sends an HTTP request message over the TCP connection.
Server receives the request, retrieves the object, and sends an HTTP response message containing the
object over the same TCP connection.
Server closes the TCP connection.
If the web page contains multiple objects (e.g., HTML file, images, CSS, JavaScript files), the client
needs to establish a new TCP connection for each object.
Pros: Simpler to implement for the server, as each connection is short-lived and independent.
Cons:
Overhead: Significant overhead due to the repeated setup and tear-down of TCP connections
(including TCP's three-way handshake and slow start).
Latency: Increased latency for fetching multiple objects on a single page, as each object requires a
new connection.
HTTP/1.0 Default: Non-persistent connections were the default behavior in HTTP/1.0.
. Persistent Connections
Mechanism: With persistent connections, the server leaves the TCP connection open after sending a
response. Subsequent HTTP requests and responses for the same client can be sent over the same open
TCP connection.
Steps:
Client initiates a TCP connection to the server.
Client sends HTTP request for the first object.
Server sends the first object.
Client sends HTTP request for the second object over the same TCP connection.
Server sends the second object over the same TCP connection.
This continues until all objects are retrieved, or a timeout occurs, after which the connection is closed.
Pros:
Reduced Overhead: Significantly reduces the overhead associated with establishing and tearing down
multiple TCP connections.
Lower Latency: Improves performance and reduces latency, especially for web pages with many
embedded objects.
TCP Congestion Control: Benefits from TCP's congestion control mechanisms, which become more
effective over long-lived connections.
Cons: Requires more complex server logic to manage open connections.
HTTP/1.1 Default: Persistent connections are the default behavior in HTTP/1.1 and later versions (HTTP/2,
HTTP/3). HTTP/1.1 allows for multiple requests to be "pipelined" (sent one after another without waiting for a
response) over a single persistent connection, further improving efficiency.
HTTP Message Format
HTTP messages are simple, human-readable text messages.
There are two primary types of HTTP messages: request messages (sent by the client) and
response messages (sent by the server).
Both message types generally follow a similar structure:
. HTTP Request Message
Format
A client sends an HTTP
request message to a server
to request a resource or to
submit data.
•Request Line: The first line of the request message. It consists of three parts,
separated by spaces:
1. Method: Indicates the desired action to be performed on the resource. Common
methods include:
GET: Requests a representation of the specified resource. (e.g., GET
/index.html HTTP/1.1)
POST: Submits data to be processed to the identified resource. (e.g., for
submitting form data)
HEAD: Asks for a response identical to that of a GET request, but without
the response body. Used for retrieving meta-information about the
resource.
PUT: Uploads a representation of the specified resource.
DELETE: Deletes the specified resource.
2. URI (Uniform Resource Identifier): The path to the requested resource on the
server (e.g., /images/logo.png).
3. HTTP Version: The version of the HTTP protocol being used (e.g., HTTP/1.1)
1. Header Fields (Headers): These lines provide additional information about the request
or the client.
Each header consists of a Name: Value pair. Some common request headers:
Host: Specifies the domain name of the server (mandatory in HTTP/1.1).
User-Agent: Identifies the client software (e.g., browser name and version).
Accept: Indicates media types that are acceptable for the response.
Accept-Language: Indicates preferred human languages for the response.
Connection: Specifies whether the connection should be persistent or non-persistent
(keep-alive or close).
Content-Type: For POST requests, specifies the media type of the message body.
Content-Length: For POST requests, specifies the size of the message body in bytes.
Cookie: Contains HTTP cookies previously sent by the server.
2. Blank Line: A single empty line (CRLF) separates the header fields from the message
body. This blank line is crucial as it signals the end of the headers.
3. Message Body (Optional): Contains data being sent to the server, typically used with
POST and PUT methods (e.g., form data, file content).
Example HTTP Request:
GET /index.html HTTP/1.
Example HTTP Request:
HTTP Response Message Format
A server sends an HTTP response message back to the client in response to a
request.
Status Line: The first line of the response message. It consists of three parts,
separated by spaces:
HTTP Version: The version of the HTTP protocol used by the server.
Status Code: A three-digit integer indicating the result of the request.
Reason Phrase: A brief, human-readable text explanation of the status
code.
Common Status Codes:
200 OK: The request has succeeded.
301 Moved Permanently: The requested resource has been
permanently moved to a new URL.
302 Found: The requested resource is temporarily under a different
URI.
400 Bad Request: The server cannot understand the request due to
malformed syntax.
404 Not Found: The server cannot find the requested resource.
500 Internal Server Error: The server encountered an unexpected
condition that prevented it from fulfilling the request.
503 Service Unavailable: The server is currently unable to handle the
request due to a temporary overload or maintenance.
Header Fields (Headers): Provide additional information about the
response, the server, or the resource being sent. Some common
response headers:
Server: Identifies the server software.
Date: The date and time the response was generated.
Content-Type: The media type of the resource in the message body
(e.g., text/html, image/jpeg).
Content-Length: The size of the message body in bytes.
Last-Modified: The date and time the resource was last modified.
Set-Cookie: Used to send cookies from the server to the client.
Connection: Specifies whether the connection should be kept alive
(keep-alive) or closed (close).
Blank Line: A single empty
line (CRLF-Carraige Return
Line Feed ) separates the
header fields from the
message body.
Message Body (Optional):
Contains the actual
requested resource (e.g.,
HTML content, image data,
JSON data). For HEAD
requests, the body is empty.
Understanding HTTP's connection types and message formats is fundamental to
comprehending how the web operates and how web applications interact with each
other.
It provides the basis for delving into more advanced web technologies and protocols.
User-Server Interaction
Cookies, Web Caching, The Conditional GET, File Transfer: FTP Commands & Replies,
Cookies
Imagine you go to a new website, say an online store. You add a few items to your shopping cart.
Then you close your browser. When you open the browser again and go back to the same store,
those items are still in your cart! How did that happen? That's thanks to cookies.
•What they are: Cookies are tiny text files that websites send to your web browser. Your browser
then stores these little files on your computer.
What they do:
Remembering you: They help websites "remember" who you are, so you don't have to log
in every time you visit.
Personalization: They can remember your preferences, like what language you prefer or
what items you've looked at, to give you a more personalized experience.
Shopping carts: As in our example, they keep track of items in your shopping cart.
Tracking: Sometimes, they can be used to track your Browse habits across different
websites, which is why you might see ads for something you just searched for.
Think of it like: A sticky note that a website leaves on your computer so it remembers things
about you for your next visit.
Web Caching
Have you ever noticed that a website loads really fast the second time you visit it, even if it was
slow the first time? That's web caching at work!
What it is: Web caching is like having a "local copy" of parts of a website saved closer to you
(either on your own computer or on a nearby server).
How it works:
When you visit a website for the first time, your browser downloads all the website's
components (images, text, videos, etc.) from the web server.
It then stores some of these components in a temporary storage area called a "cache."
The next time you visit the same website, your browser first checks its cache. If it finds the
components there and they haven't changed, it uses those local copies instead of
downloading them again from the internet.
Why it's useful:
Faster loading: Websites load much quicker because less data needs to be downloaded.
Less internet usage: It saves your internet data plan.
Reduced server load: Web servers don't have to send the same information repeatedly to
every user, making them more efficient.
Think of it like: You're borrowing a book from a library. The first time, you have to go to the main
library (the web server). But if you plan to re-read parts of it, you might make photocopies of
important pages (the cache) so you don't have to go back to the library every time.
The Conditional GET
This is a clever trick used with web caching to make sure you always have the most up-to-date
information, even with cached copies.
The problem: What if the website's content has changed since you last visited? Your cached
copy would be old!
The solution (Conditional GET): When your browser has a cached copy, instead of just asking
"Give me this page," it sends a "Conditional GET" request to the web server. This request basically
says: "Give me this page only if it has been updated since I last downloaded it (e.g., on July 1st)."
Or, "Give me this page only if its unique identifier (called an ETag) has changed."
How the server responds:
If the content has changed, the server sends the new full content.
If the content has NOT changed, the server sends a very small message saying "Not Modified"
(HTTP status code 304). This tells your browser to just use its existing cached copy.
Why it's useful: It's the best of both worlds: fast loading from the cache, but always updated if
there's new information. It saves even more bandwidth than just plain caching because if nothing
has changed, only a tiny message is sent over the network.
Think of it like: Before you start reading your photocopied book pages (cache), you quickly call
the library (web server) and ask, "Has this book been updated since I last copied it?" If they say
"No," you just read your copies. If they say "Yes," you go get the new version.
File Transfer: FTP Commands & Replies
Imagine you need to send a big file (like a document or an
image) from your computer to a server, or download one
from a server to your computer. That's where File Transfer
Protocol (FTP) comes in.
What it is: FTP is a set of rules (a protocol) that computers
use to send and receive files over a network, like the internet.
How it works (simplified):
You (the client) connect to an FTP server.
You "talk" to the server using specific commands.
The server "talks back" using specific replies.
FTP Commands (What you tell the server to do):
These are like instructions you give to the server.
USER [username]: To tell the server your username.
PASS [password]: To tell the server your password.
LIST: To ask the server to show you all the files and folders in the
current directory. (Like ls on Linux or dir on Windows)
CWD [directory name]: To change the current working directory on
the server. (Like cd on Linux/Windows)
GET [filename]: To download a file from the server to your
computer.
PUT [filename]: To upload a file from your computer to the server.
QUIT: To end your connection to the FTP server.
FTP Replies (What the server tells you back): These are numerical codes (usually 3 digits)
followed by a short message, telling you if your command was successful or if there was an error.
220: "Service ready for new user." (Means the server is ready for you to log in)
230: "User logged in, proceed." (Means you successfully logged in)
200: "Command okay." (General success message)
150: "File status okay; about to open data connection." (Preparing to send/receive a
file)
226: "Closing data connection. Requested file action successful." (File transfer
completed)
421: "Service not available, closing control connection." (Server is shutting down or
too busy)
530: "Not logged in." (You tried to do something without logging in, or your login failed)
550: "Requested action not taken. File unavailable (e.g., file not found, no access)."
(You tried to access a file that doesn't exist or you don't have permission for)
Think of it like: Calling a specific person (the FTP server) on the phone. You speak in a
specific language (FTP commands) to ask them to do things with files, and they respond
in that same language (FTP replies) to tell you if they did it or why they couldn't.
Electronic Mail in the Internet
SMTP, Comparison with HTTP, Mail Message Format, Mail Access Protocols
Electronic Mail, commonly known as email, is one of the most widely used and
fundamental services on the Internet. It allows users to send and receive digital
messages across computer networks.
The system operates on a "store-and-forward" model, meaning messages are
temporarily stored on mail servers before being delivered to the recipient's inbox,
allowing for asynchronous communication (sender and receiver don't need to be
online simultaneously).
SMTP (Simple Mail Transfer Protocol)
Purpose: SMTP is the internet standard protocol for sending electronic mail. It acts
like the postal service for email, responsible for transferring messages from the
sender's email client to their mail server, and then from one mail server to another
until it reaches the recipient's mail server.
How it Works (Simplified Flow):
1.Sender's Mail Client to Sender's Mail Server: When you click "Send" in your
email client (e.g., Outlook, Gmail web interface), your client connects to your
outgoing mail server (an SMTP server).
2.Sender's Mail Server to Recipient's Mail Server: Your outgoing mail server then
uses DNS (Domain Name System) to look up the Mail Exchange (MX) record for the
recipient's domain. This record tells the server where the recipient's mail server is
located. Once found, your mail server establishes an SMTP connection with the
recipient's mail server.
3.Message Transfer: The message, along with header information (sender, recipient,
subject, etc.), is transferred using a series of SMTP commands (e.g., HELO/EHLO for
greeting, MAIL FROM for sender, RCPT TO for recipient, DATA for the message body).
4.Delivery to Recipient's Inbox: Once the message arrives at the recipient's mail
server, it's stored in the recipient's inbox, waiting to be retrieved by the recipient's
mail client using a mail access protocol (like POP3 or IMAP).
Key Characteristics:
Push Protocol: SMTP is primarily a "push" protocol,
meaning the sender's server "pushes" the email to the
recipient's server.
Text-based: Historically, SMTP messages were restricted to
7-bit ASCII text. Multipurpose Internet Mail Extensions
(MIME) were introduced to allow for non-text content
(attachments, HTML formatting) to be sent over SMTP.
Ports: SMTP typically uses port 25 for server-to-server
communication and port 587 (or sometimes 465 for implicit
SSL/TLS) for client-to-server submission, often with
authentication.
Comparison with HTTP
Both SMTP and HTTP are application-layer protocols that facilitate communication over the Internet, but
they serve different primary purposes and have distinct characteristics
Feature SMTP HTTP
Accessing web pages, transferring files, and general client-
Primary Use Sending and relaying email messages.
server communication on the World Wide Web.
Protocol Type Primarily a push protocol (sender initiates). Primarily a pull protocol (client requests, server responds).
25 (server-to-server), 587 (client submission,
Default Ports 80 (HTTP), 443 (HTTPS - HTTP over SSL/TLS).
with TLS), 465 (implicit TLS).
Persistent TCP connection (can send multiple Can be persistent or non-persistent (for older HTTP
Connection Model
messages over one connection). versions, a new connection for each object).
Originally 7-bit ASCII, uses MIME for binary Can handle any type of data (text, images, video, etc.)
Content Handling
data/attachments. natively.
Generally stateless for message transfer, but a
Primarily stateless (each request is independent), but
Statefulness session is maintained for the duration of a
"state" is managed through cookies and sessions.
single email transfer.
Often requires authentication for clients Can use various authentication methods (Basic, Digest,
Authentication
sending mail (SMTP AUTH) to prevent spam. OAuth) for secure access.
Provides error reports (bounce messages) if Returns status codes (e.g., 200 OK, 404 Not Found, 500
Error Handling
delivery fails. Internal Server Error).
Yes, messages are stored on mail servers No, direct request-response, though content might be
Store-and-Forward
before delivery. cached.
Mail Message Format
The format of an email message is defined by RFC 5322 (Internet Message Format) and its extensions,
particularly MIME (Multipurpose Internet Mail Extensions). An email message fundamentally consists of two
main parts:
1.Header:
Contains control information about the message.
Each header field consists of a name and a value, separated by a colon (e.g., From:
[email protected]).
Common Header Fields:
From:: The email address of the sender.
To:: The primary recipient(s) of the message.
Cc: (Carbon Copy): Additional recipients who receive a copy, visible to all other recipients.
Bcc: (Blind Carbon Copy): Recipients who receive a copy, but their addresses are not visible to other
recipients.
Subject:: A brief summary of the message's topic.
Date:: The date and time the message was sent.
Message-ID:: A unique identifier for the message.
Received:: Traces the path of the message through mail servers.
Content-Type:: (Added by MIME) Specifies the type of content in the message body (e.g., text/plain,
text/html, multipart/mixed for attachments).
MIME-Version:: (Added by MIME) Indicates the MIME version used.
Content-Transfer-Encoding:: (Added by MIME) Specifies how the content is encoded for transmission
(e.g., base64, quoted-printable).
Body: ( of Mail Message format)
Contains the actual content of the message.
Can be plain text, HTML, or multiple parts (e.g., text + attachments) as defined
by MIME.
MIME (Multipurpose Internet Mail Extensions):
MIME revolutionized email by allowing non-ASCII content to be sent. It defines:
Content Types: Specifies the type of data (e.g., image/jpeg, audio/mpeg,
application/pdf).
Multi-part messages: Allows an email to contain multiple parts, such as a plain
text version, an HTML version, and one or more attachments, all within a single
message.
Encoding Schemes: Defines methods like Base64 or Quoted-Printable to convert
binary data (like images or documents) into a text-based format that can be safely
transmitted over SMTP, and then decoded by the recipient's client.
Mail Access Protocols
Once an email reaches the recipient's mail server via SMTP, mail access protocols are used by
the recipient's email client to retrieve and manage these messages.
The two most common are POP3 and IMAP.
1.POP3 (Post Office Protocol version 3)
Concept: POP3 is designed for a single client to retrieve mail from a server. It's like a post
office box: you go, collect your mail, and it's removed from the box.
How it Works: When your email client connects to the POP3 server, it typically downloads all
new messages to your local device and then deletes them from the server.
Advantages:
Offline Access: Once downloaded, messages are on your local device and can be
accessed offline.
Saves Server Space: Messages are removed from the server, freeing up space.
Disadvantages:
Device-Specific: If you access mail from multiple devices, messages downloaded to one
device won't be available on others (unless you configure the client to leave a copy on the
server, which negates some of the space-saving benefits).
No Server-Side Organization: Folders, read/unread status, and other organization are
typically local to the client.
IMAP (Internet Message Access Protocol)
Concept: IMAP is designed to allow multiple clients to access and manage mail on a
server. It's more like a remote file system: messages remain on the server, and your
client interacts with them there.
How it Works: When your email client connects to an IMAP server, it synchronizes
with the server. Messages, folders, read/unread status, flags, etc., are all managed on
the server. The client downloads copies of messages on demand (e.g., when you open
one).
Advantages:
Multi-Device Synchronization: All changes (reading, deleting, moving to folders)
are reflected across all devices accessing the same account.
Server-Side Storage: Messages are stored on the server, providing a central
backup and allowing access from anywhere with an internet connection.
Better for Webmail: Webmail clients (like Gmail, Outlook.com) inherently use an
IMAP-like model.
Disadvantages: ( of IMAP)
Requires Internet Connection: You generally need an active
internet connection to access your mail, as messages are primarily
stored on the server.
Can Consume More Server Space: Messages remain on the
server unless explicitly deleted.
In summary:
SMTP is for sending emails.
POP3 is for downloading emails to a single device and often removing
them from the server.
IMAP is for synchronizing emails across multiple devices, keeping them
on the server for central access and management.
Socket Programming: creating Network Applications: Socket
Programming with UDP, Socket,Programming with TCP
Socket programming is a fundamental concept in
creating network applications, allowing different
processes to communicate over a network.
This involves using "sockets," which are endpoints
for sending and receiving data across a network.
We'll explore socket programming with both UDP
(User Datagram Protocol) and TCP (Transmission
Control Protocol).
Key Concepts in Socket Programming:
Socket: An abstract representation of a network communication endpoint. It's a
combination of an IP address and a port number.
IP Address: A unique numerical label assigned to each device connected to a
computer network that uses the Internet Protocol for communication.
Port Number: A 16-bit number that identifies a specific process or service running on
a host.
Client-Server Model: The most common model for network applications, where a
"server" provides a service and "clients" connect to the server to use that service.
Binding: Associating a socket with a specific IP address and port number.
Listening: (TCP only) A server socket enters a listening state, waiting for incoming
client connections.
Connecting: (TCP only) A client socket attempts to establish a connection with a
server socket.
Sending/Receiving: Transmitting and getting data over the network.
Closing: Releasing the resources associated with a socket.
Socket Programming with UDP (User Datagram Protocol)
UDP is a connectionless, unreliable protocol. This means:
Connectionless: No handshake is required before sending
data. Each datagram is sent independently.
Unreliable: There's no guarantee that data will arrive, or
arrive in order, or without duplication. Error checking is
minimal.
Faster: Due to its simplicity and lack of overhead, UDP is
generally faster than TCP.
Best for: Applications where speed is more critical than
reliability, such as streaming video/audio, online gaming,
DNS queries.
UDP Server Workflow:
1.Create Socket: socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
•AF_INET: Specifies the address family (IPv4).
•SOCK_DGRAM: Specifies a UDP socket.
2.Bind: socket.bind((IP_ADDRESS, PORT))
•Associates the socket with a specific IP address and port.
3.Receive Data: socket.recvfrom(BUFFER_SIZE)
•Waits to receive a datagram and returns the data along with the
sender's address.
4.Send Data (optional): socket.sendto(DATA, ADDRESS)
•Sends a datagram back to the client.
5.Close Socket: socket.close()
UDP Client Workflow:
1.Create Socket: socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
2.Send Data: socket.sendto(DATA, (SERVER_IP, SERVER_PORT))
•Sends a datagram to the specified server. No explicit connect() is
needed.
3.Receive Data (optional): socket.recvfrom(BUFFER_SIZE)
•Waits to receive a datagram from the server.
4.Close Socket: socket.close()
Example (Python - Conceptual):
UDP Server:
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.bind((HOST, PORT))
print(f"UDP Server listening on {HOST}:{PORT}")
while True:
data, addr = s.recvfrom(1024) # Buffer size is 1024 bytes
print(f"Received {data.decode()} from {addr}")
s.sendto(b"Hello from UDP Server!", addr)
UDP Client:
import socket
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
as s:
message = b"Hello UDP Server!"
s.sendto(message, (HOST, PORT))
data, addr = s.recvfrom(1024)
print(f"Received {data.decode()} from {addr}")
Socket Programming with TCP (Transmission Control Protocol)
TCP is a connection-oriented, reliable protocol. This means:
Connection-Oriented: A connection (a virtual circuit) is
established between the client and server before data transfer
begins (three-way handshake).
Reliable: Guarantees that data will arrive, in order, and without
errors. It handles retransmissions, flow control, and congestion
control.
Slower: Due to the overhead of connection establishment and
reliability mechanisms, TCP is generally slower than UDP.
Best for: Applications where data integrity and order are crucial,
such as web Browse (HTTP), email (SMTP, POP3, IMAP), file transfer
(FTP).
TCP Server Workflow:
1.Create Socket: socket.socket(socket.AF_INET, socket.SOCK_STREAM)
•AF_INET: Specifies the address family (IPv4).
•SOCK_STREAM: Specifies a TCP socket.
2.Bind: socket.bind((IP_ADDRESS, PORT))
•Associates the socket with a specific IP address and port.
3.Listen: socket.listen(BACKLOG)
•Puts the server socket into listening mode, waiting for incoming connections. BACKLOG specifies the
maximum number of queued connections.
4.Accept: conn, addr = socket.accept()
•Waits for an incoming connection. When a client connects, it returns a new socket object (conn)
representing the connection to that client, and the client's address (addr). The original server socket
continues to listen for new connections.
5.Receive Data: data = conn.recv(BUFFER_SIZE)
•Receives data from the connected client.
6.Send Data: conn.sendall(DATA)
•Sends data to the connected client. sendall ensures all data is sent.
7.Close Connection Socket: conn.close()
•Closes the specific connection with the client.
8.Close Server Socket: socket.close() (after all connections are handled)
TCP Client Workflow:
1.Create Socket: socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
2.Connect: socket.connect((SERVER_IP, SERVER_PORT))
•Establishes a connection with the specified server.
3.Send Data: socket.sendall(DATA)
•Sends data to the connected server.
4.Receive Data: data = socket.recv(BUFFER_SIZE)
•Receives data from the server.
5.Close Socket: socket.close()
Example (Python - Conceptual):
TCP Server:
import socket
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
print(f"TCP Server listening on {HOST}:{PORT}")
conn, addr = s.accept() # Accept a single connection
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
print(f"Received {data.decode()}")
conn.sendall(b"Hello from TCP Server!")
TCP Client:
import socket
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
message = b"Hello TCP Server!"
s.sendall(message)
data = s.recv(1024)
print(f"Received {data.decode()}")
Important Considerations:
Error Handling: In real-world applications, robust error handling (e.g., using try-except blocks for
socket.error or ConnectionRefusedError) is crucial.
Blocking vs. Non-blocking Sockets: By default, sockets are "blocking," meaning an operation
(like recv or accept) will wait until it completes. For more complex applications, "non-blocking"
sockets or techniques like select, poll, or asynchronous I/O (e.g., asyncio in Python) are used to
handle multiple connections concurrently without blocking the main thread.
Serialization/Deserialization: When sending complex data structures (objects, lists,
dictionaries) over a socket, you need to convert them into a byte stream (serialization, e.g., using
JSON, pickle, or custom protocols) before sending, and then convert them back (deserialization)
on the receiving end.
Network Byte Order: Different computer architectures store multi-byte values in different byte
orders. Network protocols typically specify a "network byte order“ to ensure interoperability.
Python's socket module generally handles this for common operations.
Security: For sensitive data, consider using encrypted connections (e.g., SSL/TLS) on top of TCP.
Python's ssl module can be used for this.
Socket programming provides the foundation for building almost any network-aware application.
Understanding the differences between UDP and TCP is key to choosing the right protocol for your
specific needs.
Module 1 : Sample Questions
Exam Questions: Application Layer in Computer Networks
Q1. Explain the differences between non-persistent and persistent HTTP connections with an
example.
Q2. What is the role of the Application Layer in the OSI model? List three application-layer protocols.
Q3. Compare the services provided by the transport layer to applications in terms of reliability,
ordering, and congestion control. Distinguish between TCP and UDP in this context.
Q4. Explain the use of cookies in HTTP communication. What kind of information is stored in
cookies, and how does it enhance user-server interaction?
Q5. Describe the client-server and peer-to-peer architectures. Provide real-world examples for
each.
Q6. Write the format of a HTTP GET request message and explain each component.
Q7. What is FTP? List and explain any four commonly used FTP commands and replies.
Q8. Explain how SMTP works for sending email. Compare SMTP with HTTP in terms of connection
mode, data transfer, and message format.
Q9. Write a basic program structure for TCP socket programming in Python or C. Describe the
purpose of each function used.
Q10. What is web caching? Explain how web caching helps in reducing the response time and
network bandwidth usage with the help of a diagram.