UNIT 2-2
UNIT 2-2
Application Layer
Application Layer
Principles of Network Applications,
The Web and HTTP,
Electronic Mail in the Internet,
DNS-
The Internet’s Directory Service,
Socket Programming: Creating
Network Applications
The application layer allows users to
send each other files through a
network.
Network Application
1.Non-persistent HTTP
2.Persistent HTTP
Non-Persistent HTTP:
• For each request, a new
connection is established.
• Once the server sends the response,
the connection is closed.
• If multiple objects (like images, CSS
files) are needed, a separate
connection is created for each.
• Slower, as connection setup (like
TCP handshake) happens repeatedly.
• Example: Older HTTP versions, like
HTTP/1.0.
Fig: Non – persistent HTTP
RTT (Round-Trip Time) is the time it takes for a signal (such as
a packet of data) to travel from a sender (e.g., a client) to a
receiver (e.g., a server) and back again to the sender.
Non-Persistent HTTP:
1.Connection Establishment:
For each request, a new connection is established using TCP,
which requires a 3-way handshake (1 RTT).
2.Request and Response:
After the connection is established, the client sends the
request, and the server sends the response (another RTT).
3.Closing the Connection:
Once the response is received, the connection is closed. If
there are multiple objects (e.g., images, stylesheets), the
above process is repeated for each object.
4.Total RTT for each object = 2 RTTs (1 for handshake +
1 for request/response).
For multiple objects, the RTT multiplies quickly since each
object needs its own connection.
Persistent HTTP:
Non-Persistent HTTP:
6 Connections = 6 x (1 RTT for
handshake + 1 RTT for
request/response) = 12 RTTs.
Persistent HTTP:
1 Connection = 1 RTT (handshake)
+ 6 x (1 RTT for request/response) =
7 RTTs.
HTTP Message Format
Two types:
1.Request Message
2.Response Message
1. 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
Each message is followed by a carriage
return and a line feed.
heade
r
lines
1.Status Line:
•HTTP/1.1: The version of the HTTP protocol.
•200: The status code, meaning "OK" (the request
was successful).
•OK: phrase describing the status.
2.Header Lines:
•Extra details about the response:
•Connection: Tells the browser to close the
connection after sending.
•Date: When the response was sent.
•Server: The type of server (e.g., Apache).
•Last-Modified: When the requested file was
last updated.
•Content-Length: Size of the response in bytes
(here, 6821).
•Content-Type: The type of content being sent
(e.g., text/html).
3.Data:
•The actual file or data the browser asked for (e.g.,
an HTML webpage).
General format of an HTTP response
message
In below example, the status line indicates
that the server is using HTTP/1.1 and that
everything is OK.
1. HTTP/1.1 200 OK
HTTP/1.1: Indicates the HTTP version used.
200 OK: Status code indicating the request was successful.
2. Date:
Indicates the date and time the response was generated (Sun, 26 Sep
2010 20:09:20 GMT).
3. Server:
Provides information about the server software (Apache/2.0.52 with
CentOS).
4. Last-Modified:
The timestamp of when the requested resource was last modified (Tue,
30 Oct 2007 17:00:02 GMT).
5. ETag:
A unique identifier for the specific version of the resource ("17dc6-a5c-
bf716880").
6. Accept-Ranges:
Indicates whether the server accepts partial requests for the resource
(bytes).
7.Content-Length:
The size of the response body in bytes (2652).
8.Keep-Alive:
Details about the connection persistence:
timeout=10: The server will keep the connection open for 10
seconds.
max=100: The maximum number of requests allowed on this
connection.
9.Connection:
States whether the connection should remain open (Keep-Alive).
10.Content-Type:
Specifies the media type of the response (text/html) and the
character set (ISO-8859-1).
11.Data:
The actual content or body of the response follows the headers
(e.g., data data data ...).
User-Server interactions: Cookie
HTTP cookies (also called web cookies, Internet
cookies, browser cookies, or simply cookies)
are small blocks of data created by a web server while
a user is browsing a website and placed on the user's
computer or other device by the user's web browser.
Cookies are placed on the device used to access a
website, and more than one cookie may be placed on a
user's device during a session.
Unique ID
Entry in backend database for ID
Web caches (proxy server)
The web server sends the image to the cache with details
like the last-modified date.
HTTP/1.1 200 OK
Date: Sat, 8 Oct 2011 15:39:29
The cache saves the image and its last-modified date, then
forwards the image to the browser.
2.One Week Later (Cache Check):
Another browser requests the same image (kiwi.gif).
The image is already in the cache, but the cache checks if
the image has been updated on the web server since the
last time it was cached.
3.Conditional GET:
User Agents:
Applications that allow users to compose,
send, and read emails (e.g., Gmail,
Outlook).
Mail Servers:
Servers that store and forward email
messages between users.
1.From:
Displays the sender's email address (e.g., "Kræn Vesterberg Hansen
[email protected]"). This is the person sending the email.
2.To:
The recipient's email address (e.g., "[email protected]"). This is where the email
will be delivered.
3.Cc (Carbon Copy):
Additional email addresses (e.g., "[email protected]") where a copy of the email will
be sent. Everyone on the "Cc" list will see the email.
4.Bcc (Blind Carbon Copy):
Another list of email addresses (e.g., "[email protected]"). People here will also
receive a copy, but their addresses will stay hidden from other recipients.
5.Subject:
A short title or description of the email (e.g., "It works with a subject"). This
helps the recipient understand what the email is about.
6.Body:
The main content of the email. In this case, the text says, "It works with a body
as well."
7.Formatting Toolbar:
Tools to format the email content, such as bold, italic, underline, text alignment,
adding links, etc.
8.Buttons:
1. Send: Sends the email to the recipients.
2. Save Now: Saves the draft of the email to edit or send later.
Email
user
agent
mail user
server agent
SMTP mail user
server agent
SMTP
SMTP user
agent
mail
server
user
agent
user
agent
Outgoing
message queue
user mailbox
1.User Agent (Sender):
You use an email app like Gmail or Outlook to write and send an
email.
2.Sender's Mail Server:
After you click "Send," your email goes to your mail server. The
mail server holds your email for a short time in its outgoing
queue.
3.SMTP (Mail Transfer):
The SMTP protocol is like a mailman. It takes your email from
your mail server and delivers it to the recipient's mail server.
4.Recipient's Mail Server:
The recipient's mail server receives your email and stores it in
the recipient’s inbox.
5.User Agent (Recipient):
The recipient opens their email app (like Yahoo Mail) to read the
email.
Email Flow
POP3
Post Office Protocol – Version 3. POP3 ports are 110 and 995. Port
110 is the default, non-encrypted port, while port 995 is the encrypted
port.
IMAP
Internet Mail Access Protocol.ports
are 143 for unencrypted
communication and 993 for encrypted communication
SMTP
https://www.youtube.com/watch?v=bKECC0DHe9Y
DNS - Domain Name System
Alphabetic name
IP Address
remember by human
The client first contacts one of the root servers(tells the DNS
client where to find the Top-Level Domain (TLD) server
(e.g., .com, .org, .net), which returns IP addresses for TLD
servers - top-level domain .com.
"a Verisign, Dulles, VA": Refers to the root server managed by Verisign in Dulles, Virginia.“
m WIDE Tokyo": Refers to a root server operated by the WIDE project in Tokyo.
Why Distributed DNS is Preferred Over
Centralized DNS:
Avoid Single Point of Failure:If one DNS server
crashes, the entire Internet doesn’t go down.A
distributed system ensures that other servers can
handle the load and queries.
Handles High Traffic:Millions of devices globally use
DNS at the same time.A single server would get
overloaded, but distributing the load across multiple
servers prevents this.
Faster Response for Clients:A single server (e.g., in
New York) cannot be "close" to all users
worldwide.Queries from distant places like Australia
would face delays over slow or congested
networks.With distributed DNS, users are directed to
nearby servers, reducing latency.
Easier Maintenance:A centralized server would need
DNS name resolution
example root DNS server
Iterated query:(In an
iterative query, the 2
3
DNS resolver asks TLD DNS server
4
multiple DNS servers
one by one until it 5
gets the answer.) local DNS server
A host at cis.poly.edu dns.poly.edu
7 6
wants IP address for 1 8
gaia.cs.umass.edu
authoritative DNS server
dns.cs.umass.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
DNS name resolution
example root DNS server
Recursive query:(the
2 3
DNS resolver asks a 7
server to handle the 6
entire process of TLD DNS
server
finding the answer.)
A host at local DNS server
dns.poly.edu 5 4
cis.poly.edu wants IP
address for 1 8
gaia.cs.umass.edu
authoritative DNS server
Heavy load at upper dns.cs.umass.edu
level of hierarchy. requesting host
cis.poly.edu
gaia.cs.umass.edu
DNS Services
Real-World Applications of DNS
1.Host Aliasing
A complicated hostname like server1234.us-east-
2.aws.amazon.com can have a simple alias like
aws.amazon.com for users to remember.
2.Mail Server Aliasing
Email applications like Gmail use DNS to map
smtp.gmail.com to the server's IP address (e.g.,
142.250.115.109) for sending and receiving emails.
3.Load Distribution
Popular websites like YouTube or Netflix use DNS to
balance traffic between multiple servers.
•For example:
•www.netflix.com can resolve to
52.94.163.12 and 52.94.165.21, directing
users to different servers to avoid
overloading one server.
DNS Records
1.A Record (Address Record)
Maps a domain name to an IPv4 address.
• Example:
example.com IN A 93.184.216.34
2.AAAA Record (IPv6 Address Record)
Maps a domain name to an IPv6 address.
• Example
example.com IN AAAA
2606:2800:220:1:248:1893:25c8:1946
3.CNAME Record (Canonical Name Record)
Maps an alias domain name to the canonical domain
name.
• Example:
www.example.com IN CNAME example.com
4.MX Record (Mail Exchange Record)
Directs email to the correct mail servers for a domain.
Example:
example.com IN MX 10 mail.example.com
5.SOA Record (Start of Authority Record)
• Purpose: Provides administrative information about the
domain, including the primary DNS server and contact details.
• Example:
example.com IN SOA ns1.example.com. admin.example.com.
(
2025010801 ; Serial number
3600 ; Refresh time
1800 ; Retry time
1209600 ; Expiry time
86400 ) ; Minimum TTL
6.PTR Record (Pointer Record)
• Purpose: Maps an IP address to a domain name for reverse
DNS lookups.
• Example:
34.216.184.93.in-addr.arpa IN PTR example.com
7.SRV Record (Service Record)
• Purpose: Specifies a server for specific services, such as SIP( or
XMPP.
• Example:
_sip._tcp.example.com IN SRV 10 60 5060
SIP: Session Initiation Protocol
A signaling protocol used to initiate, maintain, and terminate real-time
communication sessions such as voice, video calls, and instant
messaging over IP networks.
XMPP: Extensible Messaging and Presence Protocol
A communication protocol for message-oriented middleware based on
XML, used for real-time messaging, presence information, and
collaboration (e.g., chat applications like WhatsApp or Slack).
DNS records
DNS: distributed database storing resource records (RR)
RR format: (name, value, type,
TTL)
type=A
▪ name is hostname
▪ value is IP address
type=NS
● name is domain (e.g., foo.com)
● value is hostname of authoritative name server for this domain
type=CNAME
▪ name is alias name for some “canonical” (the real)
name
▪ www.ibm.com is really
servereast.backup2.ibm.com
▪ value
type=MX : value is namename
is canonical of mailserver associated with
name
DNS: Caching, Updating Records
DNS Caching:
When a DNS server finds the IP address of a domain
(like "example.com"), it saves the information
temporarily to respond faster to future requests. This
saved data disappears after a set time, called TTL
(Time To Live).
Outdated Data:
If a website’s IP address changes, cached information
may still show the old IP until it updates. This can cause
delays.
Proposed Updates:
DNS protocol, messages
● query and reply messages, both with same
message format
❖ Msg header
Inserting records into DNS
1.Register the Domain Name:
• The registrar adds two Resource Records (RRs) to the .com Top-
Level Domain (TLD) server:
• NS Record: Specifies the name server responsible for the domain.
Example:(networkutopia.com, dns1.networkutopia.com, NS)
• A Record: Links the name server's domain to its IP
address.Example:(dns1.networkutopia.com, 212.212.212.1, A)
Types of Sockets:
application application
socke proc controlled by
proc app
ess
t ess developer
transport transport
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’