Unit 2_Application Layer
Unit 2_Application Layer
UNIT-2
APPLICATION LAYER
✓
Syllabus
Looping
Application Layer: Principles of computer applications, Web and
HTTP, E-mail, DNS, Socket programming with TCP and UDP
2
✓ Loopin
Outline
g
5
Network Applications - Examples
🞂Email
🞂Web
🞂Remote Login
🞂P2P File Sharing
🞂Multi-user Network Games
🞂Streaming Stored Video (YouTube)
🞂Voice Over IP (Skype)
🞂Real-time Video Conference
🞂Social Networking
6
Network Application Architecture
🞂Client-Server architecture
🞂P2P (Peer to Peer) architecture
7
Client-Server Architecture
🞂Server:
Client
⮩ It's always-on host.
⮩ It has a fixed IP address.
⮩ Large cluster of host – Data Centers.
E.g. Web Server
🞂Client:
⮩ It communicate with server.
⮩ It's not like continuously connected.
⮩ May have dynamic IP addresses.
⮩ Do not communicate directly with each other.
E.g. PCs, Mobiles
Server
8
P2P Architecture
🞂Peers (end systems) directly communicate.
Peer
🞂Get peers request service from other peers, provide
service to other peers.
⮩ Self Scalability – New peers bring new service
capacity, as well as new service demands.
Peer
Peer
9
Process Communicating
🞂 What is Process?
⮩ A process is an instance of a program running in a computer.
🞂 Process is program under execution.
🞂 Within same host, two processes communicate using inter-process communication (IPC).
🞂 Process in different hosts communicate by exchanging messages.
🞂 Client process: A process that initiates communication.
🞂 Server process: A process that waits to be contacted.
Process
Process P2
P1
10
Electronic Mail (Email)
Electronic Mail (Email)
🞂Email is an asynchronous communication medium in which people send and
read messages as convenient for them.
🞂Modern Email has many powerful features like:
⮩ A messages with attachments
⮩ Hyperlinks
⮩ HTML-formatted text
⮩ Embedded photos
🞂Email is fast, easy to distribute, and inexpensive.
🞂High level view of Internet mail system and its key components.
⮩ User agents
⮩ Mail servers
⮩ Message Transfer Agent (MTA)
12
13
Components of E-Mail System
User Agent (UA) :
🞂 The User-Agent is a simple software that sends and receives mail. It is also known as a mail reader.
🞂 It accepts variety of commands for composing, receiving and replying to messages as well as for manipulation
of the mailboxes.
Message Transfer Agent (MTA) :
🞂 The Message Transfer Agent manages the actual e-mail transfer operation (MTA).
🞂 Simple Mail Transfer Protocol sends messages from one MTA to another.
🞂 A system must have a client MTA and a system MTA to send an e-mail.
🞂 If the recipients are connected to the same computer, it sends mail to their mailboxes.
🞂 If the destination mailbox is on another computer, it sends mail to the receiver's MTA.
Mailbox :
🞂 It is a file on local hard drive to collect mails.
🞂 Delivered mails are present in this file.
🞂 The user can read it delete it according to his/her requirement.
🞂 To use e-mail system each user must have a mailbox. Access to mailbox is only to the owner of mailbox.
14
Functions of Email
Email system support 5 basic functions. They are as follows:
15
SMTP
16
1)
3)2)
4)Alice
Alice’s
Client
SMTP uses
5) Bob’suser
side user
ofagent
client
mail agent
SMTP
sendssends
serverto compose
message
Alice’s
opens
places TCP message
messageto over
her mail
the message
connection toBob’s
in
thewith
TCP
6) Bob invokes his user agent to read message
server; message
[email protected]
placed
Bob’s inserver
connection
mail
mailbox message queue.
17
Mail Access Protocols (POP3 and IMAP)
⮚ POP3
Post Office Protocol – Version 3
⮚ IMAP
Internet Mail Access Protocol
⮚ A mail access protocol, such as POP3, is used to transfer mail from the
recipient’s mail server to the recipient’s user agent.
18
POP3 – Post Office Protocol Version 3
🞂 The POP protocol stands for Post Office Protocol.
🞂 As we know that SMTP is used as a message transfer agent. When the message is sent, then
SMTP is used to deliver the message from the client to the server and then to the recipient server.
🞂 But the message is sent from the recipient server to the actual server with the help of the Message
Access Agent.
🞂 The Message Access Agent contains two types of protocols, i.e., POP3 and IMAP.
🞂 Ports of POP3
• Port 110: Port 110 is a default TCP port used by POP3. But It has a disadvantage that it does not
support encrypted communication.
• Port 995: Port 995 is majorly used for more secure applications. Port 995 is a TLS or SSL port
used to provide more security.
19
POP3 – Post Office Version 3
🞂In the case of the POP3 protocol, the POP3 client is installed on the recipient system
while the POP3 server is installed on the recipient's mail server.
🞂POP3 begins when the user agent opens a TCP connection to the mail server.
🞂After TCP connection established, POP3 progresses the phases:
⮩ Authorization
⮩ Transaction
⮩ Update
🞂In authorization, the user agent sends a username and a password to authenticate the
user.
🞂In transaction, the user agent retrieves messages, mark messages for deletion, remove
deletion marks and obtain mail statistics.
🞂In update, after the quit command by client, ending the POP3 session; the mail server
deletes marked messages.
20
Advantages of POP3 protocol
• It allows the users to read the email offline. It requires an internet connection only
at the time of downloading emails from the server. Once the mails are downloaded
from the server, then all the downloaded mails reside on our PC or hard disk of our
computer, which can be accessed without the internet. Therefore, we can say that
the POP3 protocol does not require permanent internet connectivity.
• It provides easy and fast access to the emails as they are already stored on our PC.
• There is no limit on the size of the email which we receive or send.
• There is maximum size on the mailbox, but it is limited by the size of the hard
disk.
• It is a simple protocol so it is one of the most popular protocols used today.
21
Disadvantages of POP3 protocol
• If the emails are downloaded from the server, then all the mails are deleted from the server
by default. So, mails cannot be accessed from other machines unless they are configured
to leave a copy of the mail on the server.
• Since all the attachments are stored on your local machine, there is a high risk of a virus
attack if the virus scanner does not scan them. The virus attack can harm the computer.
• The email folder which is downloaded from the mail server can also become corrupted.
• The mails are stored on the local machine, so anyone who sits on your machine can access
the email folder.
• Limited device access − POP3 does not support multiple devices accessing the same
email account simultaneously. Each device will have its own copy of the email messages,
and changes made on one device will not be reflected on other devices.
• Security concerns − POP3 does not support encrypted connections by default, and
unencrypted connections are vulnerable to interception.
22
IMAP - Internet Mail Access Protocol
🞂 To keeps all messages in one place: at server
🞂 The recipient can then move and organize the message into a new, user-created folder,
read the message, delete the message, move messages from one folder to another and so
on.
🞂 Also permit a user agent to obtain components of messages, when low-bandwidth
connection between the user agent and its mail server.
🞂 Working of IMAP:
⮩ IMAP follows Client-server Architecture and is the most commonly used email
protocol.
⮩ It is a combination of client and server process running on other computers that are
connected through a network.
⮩ This protocol resides over the TCP/IP protocol for communication.
⮩ Once the communication is set up the server listens on port 143 by default which is
non-encrypted. For the secure encrypted communication port, 993 is used.
23
Advantages & Disadvantages of IMAP
🞂Advantages :
• It provides security over POP3 protocol as the email only exists on the IMAP server.
• Users have remote access to all the contents.
• It offers easy migration between the devices as it is synchronized by a centralized
server.
• There is no need to physically allocate any storage to save contents.
🞂Disadvantages :
• IMAP is complex to maintain.
• Emails of the user are only available when there is an internet connection.
• It is slower to load messages.
• Some emails don’t support IMAP which makes it difficult to manage.
• Many browser-based solutions are unavailable due to not support of IMAP.
24
Post Office Protocol (POP3) Internet Message Access Protocol (IMAP)
Difference Between POP3 and IMAP :
❑ POP is a simple protocol that only allows ❑ IMAP (Internet Message Access Protocol) is much more
downloading messages from your Inbox to your local advanced and allows the user to see all the folders on the
computer. mail server.
❑ The POP server listens on port 110, and the POP with ❑ The IMAP server listens on port 143, and the IMAP with
SSL secure(POP3DS) server listens on port 995 SSL secure (IMAPDS) server listens on port 993.
❑ In POP3 the mail can only be accessed from a single
❑ Messages can be accessed across multiple devices
device at a time.
❑ To read the mail it has to be downloaded on the local
❑ The mail content can be read partially before downloading.
system.
❑ The user can not organize mails in the mailbox of the ❑ The user can organize the emails directly on the mail
mail server. server.
❑ The user can not create, delete or rename email on the ❑ The user can create, delete or rename an email on the mail
mail server. server.
❑ It has two modes: delete mode and keep mode.
✔ In delete mode, the mail is deleted from the mailbox ❑ Multiple redundant copies of the message are kept at the
after retrieval. mail server, in case of loss of message of a local server, the
✔ In keep mode, the mail remains in the mailbox after mail can still be retrieved
retrieval.
25
MIME (Multipurpose Internet Mail Extensions)
🞂 MIME stands for Multipurpose Internet Mail Extensions.
🞂 It is used to extend the capabilities of Internet e-mail protocols such as SMTP.
Need of MIME Protocol
MIME protocol is used to transfer e-mail in the computer network for the following reasons:
1. The MIME protocol supports multiple languages in e-mail, such as Hindi, French, Japanese, Chinese,
etc.
2. SMTP does not allow the sending of non-ASCII data but the MIME protocol is a supplementary or an
add-on protocol that allows us to send non-ASCII data over email.
3. Simple protocols can reject mail that exceeds a certain size, but there is no word limit in MIME.
4. Images, audio, and video cannot be sent using simple e-mail protocols such as SMTP. These require
MIME protocol.
5. Many marketing emails and newsletters are created using HTML and CSS to include formatting,
images, and various styles. To send such emails, the MIME standard is used, allowing multimedia
content and different formats to be included in the email body.
26
Working of MIME
27
Working of MIME
🞂 Suppose a user wants to send an email through a user agent and it is in a non-ASCII
format so there is a MIME protocol that converts it into 7-bit NVT ASCII format.
🞂 The message is transferred through the e-mail system to the other side in the 7-bit format.
🞂 Now MIME protocol again converts it back into non-ASCII code and now the user agent
of the receiver side reads it and then information is finally read by the receiver.
🞂 MIME header is basically inserted at the beginning of any e-mail transfer.
MIME with SMTP and POP
● SMTP transfers the mail being a message transfer agent from the sender’s side to the
mailbox of the receiver side and stores it. MIME adds additional headers to the email to
support non-ASCII content, multimedia attachments, and HTML formatting.
● POP being the message access agent organizes the mails from the mail server to the
receiver’s computer. POP allows the user agent to connect with the message transfer
agent, using the MIME headers to properly display the email content.
28
HTTP
(Hypertext Transfer Protocol)
HTTP
🞂 HyperText Transfer Protocol – Application layer protocol
🞂 It is implemented in two programs.
⮩ Client Program
⮩ Server Program
🞂 Exchanging HTTP message each others.
🞂 HTTP defines the structure of these messages and how web client – web server exchange
messages.
HTTP
Request
HTTP
Response
30
HTTP – Cont…
🞂HTTP
⮩ HyperText Transfer Protocol
⮩ It is Application layer protocol
HT
⮩ Client: A browser that requests, receives, PC HT
TP
req
TP ues
(using HTTP protocol) and “displays” Web (Web Browser) resp t
ons
objects. e
Mobile
(Web Browser)
31
HTTP - Cont...
🞂 A client initiates TCP connection (creates socket) to server using port 80.
🞂 A server accepts TCP connection from client.
🞂 HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client)
and Web server (HTTP server).
🞂 HTTP is “stateless protocol”
⮩ HTTP does not store the state/information of the client as well as the server.
⮩ This means that each HTTP request from a client to a server is treated as an independent
transaction that is not directly connected to any previous requests. The server does not retain
information or the "state" about the client between different requests and hence, is a stateless
protocol.
⮩ But with the help of cookies, we can make HTTP protocol as a stateful protocol.
🞂 HTTP connection types are:
⮩ Non-persistent HTTP
⮩ Persistent HTTP
32
Non-persistent & Persistent Connection
🞂 In Client-Server communication, Client making a series of requests to server, Server
responding to each of the requests.
🞂 Series of requests may be made back-to-back or periodically at regular time interval.
🞂 So, Application developer need to make an important decision;
⮩ Should each request/response pair be sent over a separate TCP connection.
OR
⮩ Should all the requests and corresponding responses be sent over same TCP
connection?
33
33
Basic Prerequisites
🞂 The terminology which we must know before going deep into Persistent & Non-Persistent Connections
is :
✔ RTT(Round Trip Time)
✔ TCP 3-Way Handshake
Round Trip Time (RTT)
🞂 Round Trip Time is defined as the time taken by a packet of information to travel from client to server
and then come back (i.e. server to client).
TCP 3-Way Handshake
🞂 The establishment of a TCP connection takes place in 3 steps which are referred to as 3-Way
Handshake. These 3 steps of the 3-Way Handshake are:
1. The client sends a request to the server to open a TCP connection on which, data can be
exchanged.
2. After receiving the request from the client, the server sends an acknowledgment to tell the client
to establish a connection.
3. The client acknowledges the response (acknowledgment sent in step 2) sent by the server. After
this, a connection is established between the client and the server and the data can be exchanged
on this connection.
34
Non-persistent HTTP
🞂A non-persistent connection is closed after the server sends the requested object to the
client.
🞂The connection is used exactly for one request and one response.
🞂For downloading multiple objects, it required multiple connections.
🞂Non-persistent connections are the default mode for HTTP/1.0.
🞂Example:
Transferring a webpage from server to client, webpage consists of a base HTML file
and 10 JPEG images and that all 11 objects are reside on the same server.
Whole process of request and response are then repeated for each of the referenced
JPEG objects.
35
Non-persistent HTTP – Cont.…
🞂 URL: www.someSchool.edu/someDepartment/home.index
time time
37
Advantages & Disadvantages of Non-Persistent HTTP
38
Persistent HTTP
🞂In a persistent connection, the client and server maintain the connection open for
multiple requests and responses.
🞂After the initial request, the connection remains open, allowing the client to send
multiple requests to the same server using the same connection.
🞂This approach reduces the overhead of opening and closing a new connection for each
request, which can significantly improve performance, especially for websites with
many resources (e.g., images, stylesheets, scripts).
🞂The server keeps the connection open for a configurable amount of time or until a
certain number of requests have been handled. Afterward, it may close the connection
or the client can request it to be closed.
🞂With persistent connections, the performance is improved by 20%.
🞂Persistent connections are the default mode for HTTP/1.1.
39
Persistent HTTP
🞂 A persistent HTTP connection can be either Non-pipelined or Pipelined.
🞂 Non-Pipelined
A non-pipelined HTTP connection is a connection in which, the client can send a request to the server only
if the previous request that was sent by the client has been acknowledged by the server.
🞂Pipelined
A pipelined HTTP connection is a connection in which, the client can send a request to the server even if
the previous request that was sent by the client has not been acknowledged by the server.
40
Advantages & Disadvantages of Persistent HTTP
42
HTTP Request Message
🞂 It is in ASCII format which means that human-readable format.
🞂 HTTP request message consist three part:
⮩ Request line
⮩ Header line
⮩ Carriage return carriage return character
request line line-feed
(GET, POST, character
GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
header Accept: text/html,application/xhtml+xml\r\n
Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
carriage return Keep-Alive: 115\r\n
and line feed at start Connection: keep-alive\r\n
of line indicates \r\n
end of header lines
43
HTTP Request Message - Format
Request Line
🞂 An HTTP request-line consists of 3 parts which
are discussed below.
▪ Request Method A request method defines what
type of request is needed to send to the web
server. For example, if we want to fetch
something from the web server, we use
a GET request method. If we want to send
something from the client to the web server, we
use POST request method.
▪ Request URI (Uniform Resource Identifier)
It is the URI of the website/destination we want
to reach. For example "http://scaler.com/".
▪ HTTP Version It states the version of the HTTP
we are using. For example HTTP 1.0, HTTP 1.1.
44
HTTP Request Message - Format
Request Headers
▪ Request headers contain additional information about the resource/data that is to be fetched
from the web server.
▪ For example, if we want the data in the plaintext format, we can specify that information in
the HTTP headers.
▪ We can also specify the information related to the client using headers like the browser it is
using etc.
▪ We can send more than one HTTP header along with an HTTP request to specify the
additional information that is to be sent along with an HTTP request.
Request Body
▪ It is an optional part of an HTTP request. If there is a requirement to send some data along
with an HTTP request, we send that data along with the HTTP Body.
▪ For example: If we want to send the details of a user which is taken through a form at the
client side to the web server, we can send this data in the HTTP body.
45
HTTP Response Message
🞂 HTTP response message consist of three part:
1. Status line
2. Header line
3. Data (Entity body)
status line
HTTP/1.1 200 OK\r\n
(protocol Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n
status code Server: Apache/2.0.52 (CentOS)\r\n
status phrase) Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT\r\n
ETag: "17dc6-a5c-bf716880"\r\n
header Accept-Ranges: bytes\r\n
lines Content-Length: 2652\r\n
Keep-Alive: timeout=10, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=ISO-8859-1\r\n
\r\n
data, e.g., data data data data data ...
requested
HTML
file
46
HTTP Response Message
47
HTTP Response Message
🞂 After the client/browser sends an HTTP request to the web server, the server responds back to the browser
with an HTTP response. This response consists of all the data that is requested by the client in
the HTTP request.
🞂 An HTTP response consists of 3 parts:
1. Response Status Line
🞂 An HTTP request line consists of 3 parts which are discussed below.
✔ HTTP Version It states the version of the HTTP we are using. For example HTTP 1.0, HTTP 1.1.
✔ Status Code It is a three-digit code that tells the status of the HTTP response. For example
code 200 stands for a successful HTTP response.
✔ Status Phrase It is a short description of the status code.
2. Response Headers
🞂 The response headers are used to specify the additional information related to the response data and the
server.
3. Response Body
🞂 It is an optional part of the HTTP response. The data which is requested by the client using
the HTTP request is sent from server to client by keeping it inside the response body.
48
HTTP Response Message - Format
🞂The status line has three fields: protocol version field, status code and corresponding
status message.
🞂In below example, the status line indicates that the server is using HTTP/1.1 and that
everything is OK.
HTTP/1.1 200 OK\r\n
Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n
Server: Apache/2.0.52 (CentOS)\r\n
Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT\r\n
ETag: "17dc6-a5c-bf716880"\r\n
Accept-Ranges: bytes\r\n
Content-Length: 2652\r\n
Keep-Alive: timeout=10, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=ISO-8859-1\r\n \r\n
data data data data data ...
Date: header
Content-Type:
Server:
Last-Modified:
Content-Length: lineheader
header indicates
header
header
line line the
indicates
line time that
indicates
indicatesandthat
indicates date
the when
thethe
number
time the
message
object
and HTTP
of in
bytes
date
was
the
response
generated
when
in
entity
the thewas
byiscreated
object
bodyobject
being
an
HTML and
Apache
wassent.sent
Webby
created
text. the
lastserver.
orserver. modified.
49
HTTP GET and HTTP POST method
GET Method
🞂The Hypertext Transfer Protocol(HTTP) Get method is mainly used at the client
(Browser) side to send a request to a specified server to get certain data or
resources.
🞂Using this method the server should only let us receive the data and not change
its state.
🞂Hence it is only used to view something and not to change it.
🞂The request parameter of the get method is appended to the URL.
🞂Get request is better for the data which does not need to be secure (It means the
data which does not contain images or word documents).
50
Continue…
POST Method
🞂The Hypertext Transfer Protocol(HTTP) Post method is mainly used at the
client (Browser) side to send data to a Specified server in order to create or
rewrite a particular resource/data.
🞂This data sent to the server is stored in the request body of the HTTP request.
🞂 Post method eventually leads to the creation of a new resource or updating an
existing one.
🞂Due to this dynamic use, it is one of the most used HTTP methods.
🞂It is one of the most secure methods because the data that is been sent is
included in the body of the request and not in the URL.
🞂Post request is better for the data which needs to be secure (It means the data
which contains images or word documents).
51
Difference between GET method and POST Method
HTTP GET HTTP POST
GET request is comparatively better than Post so it is used more POST request is comparatively less better than Get so it is used less
than the Post request. than the Get request.
GET request is comparatively less secure because the data is POST request is comparatively more secure because the data is not
exposed in the URL bar. exposed in the URL bar.
GET method request can be saved as bookmark in browser. POST method request can not be saved as bookmark in browser.
Request made through GET method are stored in cache memory of Request made through POST method are not stored in cache
Browser. memory of Browser.
In GET method only ASCII characters are allowed. In POST method all types of data is allowed.
52
Domain Name System (DNS)
Domain Name System (DNS)
⮚ DNS (Domain Name System) is an internet service that translates domain
names into IP addresses.
⮚ Every time you use a domain name, therefore, a DNS service must translate
the domain name into the corresponding IP address.
For example, the domain name www.google.com might translate to
198.105.232.4.
54
Types of Domain
58
Fully Qualified Domain Name (FQDN)
59
Example
www.example.com.
www is the hostname.
example is the domain.
com is the top-level domain (TLD).
The dot (.) at the end signifies the root of the DNS tree.
60
Key Characteristics
1) Complete and absolute:
An FQDN gives the full path, leaving no ambiguity about the location of
the resource.
2) Globally unique:
No two FQDNs can be the same across the internet.
3) Ends with a dot:
The FQDN technically ends with a dot, representing the root domain,
although the dot is often omitted in browsers and applications for
convenience.
61
Partially Qualified Domain Name (PQDN)
62
Example
www.example or simply www
The full path (FQDN) would be www.example.com. but in this case, the
TLD (.com) is missing or implied.
63
Key Characteristics
1) Incomplete path:
A PQDN is not the complete domain name. It may require additional
information to resolve fully (like assuming a default domain suffix or
local configuration).
2) Dependent on local context:
PQDNs are often resolved using DNS suffix search lists or defaults
configured in local network settings.
3) No guaranteed uniqueness:
Since it’s incomplete, a PQDN might not be globally unique without
more information to complete the domain name.
64
65
How does DNS work?
🞂The host requests for the IP address of a particular domain name to the DNS server and the IP
address is returned to the host by the DNS server.
🞂The hierarchy of the resolution of the request is shown below.
WORKING OF DNS
1) The client requests for the IP address of a
particular domain name to the DNS resolver.
2) The resolver requests to the root DNS server.
3) The root DNS server then forwards the query to
the Top-level DNS server.
4) The top-level domain server has all the
information about the authoritative DNS servers.
5) The authoritative server then returns the IP
address corresponding to the requested domain
name to the resolver.
6) The resolver then returns the IP address to the
host.
66
Why Distributed DNS is Preferred Over Centralized DNS?
1.A single point of failure:
Problem in Centralized Design:
In a centralized DNS system, a single server manages all domain-to-IP
mappings. If this server crashes or becomes unreachable, all DNS
queries would fail, and users wouldn't be able to access any websites.
Advantage of Distributed Design:
In a distributed DNS, multiple DNS servers are spread across the
globe. Even if one server crashes or fails, other servers can still
respond to queries, preventing a total failure. This ensures high
availability and fault tolerance.
67
2.Handling Traffic Volume:
Problem in Centralized Design:
The internet is massive, with billions of devices and users accessing
DNS services every second. A single DNS server would be
overwhelmed by the sheer volume of queries, causing slow response
times and potential overloads.
Advantage of Distributed Design:
In a distributed system, DNS queries are spread across many servers
located in different regions. This distribution helps balance the load
and prevents individual servers from becoming overwhelmed, ensuring
that DNS traffic can be handled efficiently on a global scale.
68
3.Geographical Proximity and Latency:
Problem in Centralized Design:
In a centralized system, the single DNS server might be located far
from some users. For example, if the DNS server is located in New
York, users in distant regions like Australia would have to send their
DNS queries halfway across the globe. This could introduce significant
latency, especially over slow or congested network links.
Advantage of Distributed Design:
In a distributed DNS, servers are located closer to users in different
geographic regions. A user in Australia, for example, can query a DNS
server located nearby, reducing latency and improving response times.
69
4.Maintenance and Scalability:
Problem in Centralized Design:
A single DNS server would need to store and manage records for all
internet hosts, which would result in a massive and constantly growing
database. Maintaining such a huge database would be complex, with
frequent updates needed as new domains are registered and IP
addresses change.
Advantage of Distributed Design:
In a distributed DNS, the responsibility for storing domain information
is shared across many servers, each maintaining only a portion of the
total DNS database. This decentralized approach reduces the
maintenance burden on any one server and makes the system much
more scalable as the internet grows.
70
🞂 A Distributed, Hierarchical Database
71
Why do HTTP, FTP, SMTP and POP3 run on top of TCP rather than UDP? Name
one application that uses UDP and why?
HTTP, FTP, SMTP, and POP3 are all application layer protocols that run on top of the transport layer
protocol, which is typically TCP (Transmission Control Protocol), rather than UDP (User Datagram
Protocol) for several reasons:
72
Why do HTTP, FTP, SMTP and POP3 run on top of TCP rather than UDP? Name
one application that uses UDP and why? (Continue….)
🞂 As for an application that uses UDP, one common example is DNS (Domain Name System). DNS is
responsible for translating human-readable domain names (like www.example.com) into IP addresses
(like 192.168.1.1).
🞂 DNS uses UDP because:
1. Speed: DNS queries and responses need to be fast because they are a fundamental part of web
browsing and other internet activities.
2. Simplicity: DNS queries are typically short and do not require the reliability and error-checking
features of TCP. If a DNS query or response is lost or corrupted, the DNS resolver or client can simply
retry the query.
3. Scalability: DNS servers often handle a large number of queries simultaneously. Using UDP allows
DNS servers to efficiently handle a high volume of requests without the overhead of managing
multiple connections.
🞂 In summary, the choice between TCP and UDP depends on the specific requirements of the
application. TCP is preferred when reliability and data integrity are crucial, while UDP is chosen for
applications that prioritize speed, simplicity, and scalability. DNS is an example of an application that
uses UDP due to its lightweight and efficient nature.
73
DNS Message Format
🞂DNS allows us to interact with devices on the Internet without having to
remember long strings of numbers.
🞂Changing of information between client and server is carried out by two
types of DNS messages:
1) Query message
2) Response message
🞂The format is similar for both types of messages.
🞂The information is held up in up to five different sections of DNS message
format.
74
DNS Message Format (Contd…)
🞂The query message is having two sections:
1) Header records
2) Question records
🞂The response message consists of five sections:
1) Header
2) Question records
3) Answer records
4) Authoritative records
5) Additional records
75
DNS Message Format (Contd…)
76
DNS Message Format (Contd…)
🞂The message has a fixed 12-byte header followed by four variable-length
fields.
Identification
🞂The identification field is made up of 16 bits which are used to match the
response with the request sent from the client-side.
🞂The matching is carried out by this field as the server copies the 16-bit
value of identification in the response message so the client device can
match the queries with the corresponding response received from the
server-side.
Flags
🞂It is 16 bits and is divided into the following Fields:
77
DNS Message Format (Contd…)
🞂QR (query/response):
⮩ It is a 1-bit subfield.
⮩ If its value is 0, the message is of request type and if its value is 1, the
message is of response type.
🞂opcode:
⮩ It is a 4-bit subfield that defines the type of query carried by a message.
This field value is repeated in the response.
⮩ Following is the list of opcode values with a brief description:
▪ If the value of the opcode subfield is 0 then it is a standard query.
▪ The value 1 corresponds to an inverse of query that implies finding
the domain name from the IP Address.
▪ The value 2 refers to the server status request.
▪ The value 3 specifies the status reserved and therefore not used.
78
DNS Message Format (Contd…)
🞂AA:
⮩ It is an Authoritative Answer.
⮩ It is a 1-bit subfield that specifies the server is authoritative if the value
is 1 otherwise it is non-authoritative for a 0 value.
🞂TC:
⮩ It is Truncation.
⮩ This is a 1-bit subfield that specifies if the length of the message
exceeds the allowed length of 512 bytes, the message is truncated when
using UDP services.
🞂RD:
⮩ It is Recursion Desired.
⮩ It is a 1-bit subfield that specifies if the value is set to 1 in the query
message then the server needs to answer the query recursively.
⮩ Its value is copied to the response message.
79
DNS Message Format (Contd…)
🞂RA:
⮩ It is Recursion Available.
⮩ It is a 1-bit subfield that specifies the availability of recursive response
if the value is set to 1 in the response message.
🞂Zero:
⮩ It is a 3-bit reserved subfield set to 0.
🞂rCode:
⮩ It stands for Response Code.
⮩ It is a 4-bit subfield used to denote whether the query was answered
successfully or not.
⮩ If not answered successfully then the status of error is provided in the
response.
80
DNS Message Format (Contd…)
81
DNS Message Format (Contd…)
Number of Questions
🞂It is a 16-bit field to specify the count of questions in the Question Section
of the message.
🞂It is present in both query and response messages.
82
DNS Message Format (Contd…)
Number of authority RRs
🞂It is a 16-bit field that gives the count of the resource records in the
Authoritative section of the message.
🞂This section has a value of 0 in query messages.
🞂It is available only in response messages.
🞂It gives information that comprises domain names about one or more
authoritative servers.
84
WEB
(WWW)
Web
🞂 Early 1990, Internet was used only by researchers, academics, and university students.
🞂 New application WWW arrived in 1994 by Tim Berners-Lee.
🞂 World Wide Web - is an information where documents and other web resources are
identified by URL, interlinked by hypertext links, and can be accessed via the Internet.
🞂 On demand available, What they want, When they want it.
🞂 Unlike TV and Radio.
86
86
Web (Contd…)
🞂Web page consists of objects.
🞂Object can be HTML file, JPEG image, audio file etc.…
🞂Web page consists of base HTML-file which includes several referenced
objects.
Web Page (e.g Total five objects)
88
System Architecture (Contd…)
89
System Architecture (Contd…)
🞂Client (Browser): This represents the user’s web browser or client device.
🞂Internet represents the network and protocols (like HTTP/HTTPS) used
for communication.
🞂Server (Web Server): This hosts the website or web application.
🞂Data Layer (Database): This stores data used by the web server.
Flow
🞂User Request: The user sends a request from the browser to the server
over the internet.
🞂Server Response: The server processes the request, retrieves data from
the database if needed, and sends a response back to the browser.
🞂Data Retrieval: The server interacts with the database to fetch or store
data.
90
Features of WWW
🞂WWW is open source.
🞂It is a distributed system spread across various websites.
🞂It is a Hypertext Information System.
🞂It is Cross-Platform.
🞂Uses Web Browsers to provide a single interface for many services.
🞂Dynamic, Interactive and Evolving.
91
Components of the Web
🞂There are 3 components of the web:
1) Uniform Resource Locator (URL): URL serves as a system for
resources on the web.
2) Hypertext Transfer Protocol (HTTP): HTTP specifies
communication of browser and server.
3) Hypertext Markup Language (HTML): HTML defines the
structure, organisation and content of a web page.
92
Components of a URL
🞂URL stands for Uniform Resource Locator.
🞂For a website, a URL is basically where the website lives online and it
helps visitors to identify the site easily as well as get an idea about its
contents.
🞂A typical website has at least 3 parts in its URL like www.google.com but
some complex URLs might also have 8 to 9 parts namely scheme,
subdomain, domain name, top-level domain, port number, path,
query, parameters, and fragment.
93
94
Difference between WWW and Internet
WWW Internet
It is originated in 1989. It is originated in 1960.
WWW is an interconnected network of websites Internet is used to connect a computer with
and documents that can be accessed via the other computer .
Internet.
WWW used protocols such as HTTP Internet used protocols such as TCP/IP
It is based on software. It is based on hardware.
The World Wide Web (WWW) is a service that The Internet is the entire global infrastructure
operates within the infrastructure of the internet. that connects millions of computers, servers,
It is a collection of web pages and resources, and networks around the world. It facilitates
accessed via protocols like HTTP and HTTPS, various services such as email, file transfer, and
allowing users to view, share, and interact with the World Wide Web.
information online.
95
User-Server interactions
Or
Cookie
User-Server Interaction OR Cookies
🞂 A small text file that is stored in the user's computer temporarily for that session only.
🞂 Cookies provide a way for the Web site to recognize you and keep track of your
preferences.
🞂 The cookie technology has four components:
1. A cookie header line in the HTTP response message
2. A cookie header line in the HTTP request message
3. A cookie file kept on the user’s end system and managed by the user’s browser
4. A back-end database at the Web site
🞂 Cookies are unique to the server, so that the user might have many cookies in their
system, but a server identifies its cookie.
Authorization Recommendations
Use of Cookies
97
98
Types of Cookie
🞂There are 2 types of cookies in servlets:-
1.Non-persistent cookie
2.Persistent cookie
1. Non-persistent cookie
🞂 It is valid for single session only.
🞂 It is removed each time when user closes the browser.
2. Persistent cookie
🞂 It is valid for multiple session .
🞂 It is not removed each time when user closes the browser.
🞂 It is removed only if user logout or sign out.
99
Uses of Cookies
• Session management – Cookies let websites allow users and recollect their
individual login information and preferences.
• Tracking – E-commerce sites use cookies to track items users previously viewed
allowing the sites to suggest other goods in which you are interested.
• Personalization – It is a customized advertising which is the main way cookies are
used to personalize your sessions.
Authorization Recommendations
Use of
Cookies
User session state
Shopping carts
(Web, Email)
100
Web Caches (Proxy Server)
Web Caching OR Proxy Server
🞂 A Web cache OR a proxy server is a network entity that satisfies HTTP requests on the behalf of an origin Web
server.
🞂 The Web cache has its own disk storage and keeps copies of recently requested objects in this storage.
🞂 Fig.: Clients requesting objects through a Web cache
🞂 A user’s browser can be configured so that all of the user’s HTTP requests are first directed to the Web cache.
🞂 As an example, suppose a browser is requesting the object http://www.someschool.edu/campus.gif.
102
Web Caches (Proxy Server) – Cont...
1. The browser establishes a TCP connection to the Web cache and sends an HTTP request for the
object to the Web cache.
2. The Web cache checks to see if it has a copy of the object stored locally. If it does, the Web
cache returns the object within an HTTP response message to the client browser.
3. If the Web cache does not have the object, the Web cache opens a TCP connection to the origin
server, that is, to www.someschool.edu. The Web cache then sends an HTTP request for the
object into the cache-to-server TCP connection. After receiving this request, the origin server
sends the object within an HTTP response to the Web cache.
4. When the Web cache receives the object, it stores a copy in its local storage and sends a copy,
within an HTTP response message, to the client browser.
⮚ Note that a cache is both a server and a client at the same time.
⮚ When it receives requests from and sends responses to a browser, it is a server.
⮚ When it sends requests to and receives responses from an origin server, it is a client.
🞂 Why Web caching is needed (Required)? OR Advantages of Caching
⮚ To reduce response time for a client request
⮚ To reduce traffic on an institution’s access link
⮚ To enable "poor" content providers to effectively deliver content
103
Socket
🞂 A socket is one endpoint of a two way communication link between two programs
running on the network.
🞂 Like ‘Pipe’ is used to create pipes and sockets is created using ‘socket’ system call
🞂 The socket provides bidirectional FIFO Communication facility over the network. A
socket connecting to the network is created at each end of the communication.
🞂 Each socket has a specific address. This address is composed of an IP address and a
port number.
104
Socket
Working
🞂Socket are generally employed in client server applications.
🞂The server creates a socket, attaches it to a network port addresses then waits
for the client to contact it.
🞂The client creates a socket and then attempts to connect to the server socket.
When the connection is established, transfer of data takes place.
Purpose of Socket
🞂Sockets are used by most input validation routers, such as FTP (File transfer
protocol), SMTP (Simple mail transfer protocol), and POP3, to create
connections among sender and receiver and then to exchange information.
105
Socket Programming with TCP
& UDP
Socket Programming
🞂 Socket is interface between application and network.
⮩ An application creates a socket.
⮩ Two type of socket:
▪ TCP Socket – Reliable Transmission
▪ UDP Socket – Unreliable Transmission
🞂 Once configured the application can pass data to the socket for transmission and receive data
from the socket (transmitted through the network by some other host).
application application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
107
Types of Socket
Stream Sockets: Stream socket allows processes to use the Transfer Control Protocol (TCP) for
communication.
A stream socket provides a sequenced, constant or reliable, and two-way (bidirectional) flow of
data.
After the establishment of connection, data can be read and written to these sockets in a byte
stream.
The socket type of stream socket is SOCK_STREAM.
⮩ E.g. TCP
⮩ Reliable delivery App
⮩ In-order guaranteed 3 2
1 socket
⮩ Connection-oriented Dest.
⮩ Bidirectional
108
Types of Socket
Datagram Sockets: Datagram sockets allow processes to use the User Datagram Protocol
(UDP).
It is a two-way flow of communication or messages.
It can receive messages in a different order from the sending way and also can receive duplicate
messages.
The socket type of datagram socket is SOCK_DGRAM.
⮩ E.g. UDP
⮩ Unreliable delivery
App D1
⮩ No order guarantees
⮩ Connection-less 3 2 1 socket D2
⮩ Unidirectional D3
109
Function Call Description
Socket() To create a socket
It’s a socket identification like
Bind()
a telephone number to contact
Listen() Ready to receive a connection
Connect() Ready to act as a sender
Confirmation, it is like
Accept() accepting to receive a call from
a sender
Write() To send data
Read() To receive data
Close() To close a connection
110
Socket Programming in TCP
🞂 TCP stands for Transmission Control Protocol. TCP is a reliable connection-oriented protocol
of the transport layer. TCP establishes the connection before data transmission. Steps for TCP
socket programming for establishing TCP socket at the client-side:
• The first step is to create a socket and use the socket() function to create a socket.
• Use the connect() function for connecting the socket to the server address.
• Transmit data between two communicating parties using read() and write() functions.
• After data transmission completion close the connection using close() function.
🞂 Following are steps to be followed for establishing a TCP socket on the server-side:
• Use socket() for establishing a socket.
• Use the bind() function for binding the socket to an address.
• Then for listening client connections use listen() function.
• The accept() function is used for accepting the connection of the client.
• Transmit data with the help of the read() and write() function.
111
Socket Programming in TCP
112
Socket Programming in UDP
🞂 UDP stands for User Datagram Protocol. UDP is a connection-less and unreliable protocol of
transport layer.
🞂 UDP does not establish a connection between two communicating parties before transmitting
the data.
🞂 Following are the steps given that are to be followed for establishing UDP socket connection
on the client-side
• Use socket() function for creating socket;
• recvfrom() and sendto() functions are used for transmitting data between two communicating
parties.
🞂 Steps to be followed for establishing UDP socket connection at the server-side.
• Create a socket using the socket() function.
• Use the bind() function for the binding socket to an address.
• Transmit data with the help of the recvfrom() function and sendto().
113
Socket Programming in UDP
114
Thank you……
115