Application Layer

Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

Module 5 Chapter 2

Application Layer
• Principles of Network Applications
• The Web and HTTP
• Electronic Mail in the Internet
• DNS—The Internet’s Directory Service
 The network application is an application running on one host and
provide a communication to another application running on a
different host.

 Network application Examples:


2.1 Principles of Network Application
 The core of network application development is writing programs that
run on different end systems and communicate with each other over
the network.
 In the Web application there are two distinct programs that
communicate with each other:
 The Browser program running in the user’s host (desktop, laptop,
tablet, smartphone, and so on); and
 The Web server program running in the Web server host.
 When developing your new application, you need to write software
that will run on multiple end systems.
 This software could be written, for example, in C, Java, or Python.

 One do not need to write software that runs on network core devices,
such as routers or link-layer switches.

 Network -core devices do not run user applications

 Network -core devices do not function at the application layer but


instead function at lower layers- specifically at the network layer and
below.
2.1.1 Network Application Architectures.
 An application’s architecture is distinctly different from the network
architecture.
 From the application developer’s perspective, the network
architecture is fixed and provides a specific set of services to
applications.

 The application architecture, on the other hand, is designed by the


application developer and dictates how the application is structured
over the various end systems.

 There are two different network application architecture, they are


1) The client-server architecture
2) The peer-to-peer (P2P) architecture
Client-Server architecture.
 In a client-server architecture, there is an always-on host, called the
server, which services requests from many other hosts, called clients.
 The client hosts can be either sometimes-on or always on, but a
server host should be always on.
 When a Web server receives a request for an object from a client
host, it responds by sending the requested object to the client host.
 Some of the better-known applications with a client-server
architecture include the Web, FTP, Telnet, and e-mail.
Peer-to-Peer Architecture (P2P)
 In P2P architecture, the application have direct communication between pairs of
intermittently connected hosts, called peers.
 In P2P architecture each computer in the network can act as a client or a server for
the other computers in the network, allowing the sharing of resources without the
need for a central server.
 Because the peers communicate without passing through a dedicated server, the
architecture is called peer-to-peer.
 These applications include file sharing/distribution (e.g., BitTorrent), Internet
telephony (e.g., Skype) etc.
 This decentralized structure allows for more efficient resource sharing. However,
more difficult to control and secure the network, as no central authority manages it.
2.1.2 Processes Communicating
 Process is a program under execution.
 Within same host, two process communicate using inter process
communication (IPC)
 Processes on two different end systems communicate with each other
by exchanging messages across the computer network.
 Client process: A process that initiates communication
 Server Process: A process that waits to be contacted
The Interface between the Process and the Computer Network
 A process sends messages into, and receives messages from, the
network through a software interface called a socket.
 The application at the sending side pushes messages through the
socket.
 At the other side of the socket, the transport-layer protocol has the
responsibility of getting the messages to the socket of the receiving
process.
 Ex: Process is similar to a house and its socket is similar to its door
Addressing Processes
 For a process running on one host to send packets to a process running
on another host, the receiving process needs to have an address.
 To identify the receiving process, two pieces of information need to be
specified:
(1) The address of the host(identified by its IP address)
(2) An identifier that specifies the receiving process in the
destination host.

 A destination port number serves this purpose. Popular applications


have been assigned specific port numbers.

 For example, a Web server is identified by port number 80. A mail


server process (using the SMTP protocol) is identified by port number
25.
Transport Services Available to Applications
• Reliable Data Transfer
• Throughput
• Timing
• Security
1) Reliable Data Transfer
 Packets can get lost within a computer network.
 For Ex: a packet can overflow a buffer or can be discarded by a host
after having some of its bits corrupted.
 For applications—such as electronic mail, file transfer, remote host
access and financial applications require 100% reliable data transfer
 Required guarantee that data sent by one end of the application is
delivered correctly and completely to the other end of the application.
 This guaranteed data delivery service is called reliable data transfer.
Throughput

 Transport-layer protocol could provide guaranteed available


throughput at some specified rate.

 the application could request a guaranteed throughput of r bits/sec,


and the transport protocol would then ensure that the available
throughput is always at least r bits/sec.

 For example, if an Internet telephony application encodes voice at 32


kbps, it needs to send data into the network and have data delivered to
the receiving application at this rate.

 If the transport protocol cannot provide this throughput, the


application would need to encode at a lower rate or may have to give
up.
Timing
 A transport-layer protocol can also provide timing guarantees.
 Interactive real-time applications, such as Internet telephony,
teleconferencing, and multiplayer games require tight timing
constraints on data delivery in order to be effective.

Security
 Transport protocol can provide an application with one or more
security services.
 For example, in the sending host, a transport protocol can encrypt all
data transmitted by the sending process, and in the receiving host, the
transport-layer protocol can decrypt the data before delivering the data
to the receiving process.
Transport Services Provided by the Internet
Application-Layer Protocols
 An application-layer protocol defines:
 The types of messages exchanged, for example, request messages and
response messages
 The syntax of the various message types ( fields in the message).
 The semantics of the fields (meaning of the information in the fields)
 Rules for determining when and how a process sends messages and
responds to messages.

Fig: Popular Internet applications, their application-layer protocols,


and their underlying transport protocols
The Web and HTTP
Web:
HTTP
Non-Persistent and Persistent Connections
 If Separate TCP connection is used for each request and response, then
the connection is said to be non persistent.
 If same TCP connection is used for series of related request and
response, then the connection is said to be persistent.

 Round-trip time (RTT) is the time it takes for a small packet to


travel from client to server and then back to the client.
 The RTT includes packet-propagation delays, packet queuing delays
in intermediate routers and switches, and packet-processing delays.
 When a user clicks on a hyperlink, the browser initiate a TCP
connection between the browser and the Web server; this involves a
―three-way handshake‖—the client sends a small TCP segment to the
server, the server acknowledges and responds with a small TCP
segment, and, finally, the client acknowledges back to the server.
 The first two parts of the three way handshake take one RTT.
 After completing the first two parts of the handshake, the client sends
the HTTP request message combined with the third part of the three-
way handshake (the acknowledgment) into the TCP connection.
 Once the request message arrives at the server, the server sends the
HTML file into the TCP connection. This HTTP request/response eats
up another RTT. Thus, roughly, the total response time is two RTTs
plus the transmission time at the server of the HTML file.
HTTP with Persistent Connections
Non-persistent connections have some shortcomings.
 1. A new connection must be established and maintained for each
requested object.

 2. Each object suffers a delivery delay of two RTTs— one RTT to


establish the TCP connection and one RTT to request and receive an
object.

 With persistent connections, the server leaves the TCP connection open
after sending a response.

 Subsequent HTTP message between same client and server can be sent
over a single persistent TCP connection.
HTTP Message Format
Two types of HTTP messages:
• Request messages and
• Response messages
 HTTP Request Message:

Where sp – space, cr – carriage return and lf – line feed


 HTTP message usually in ASCII format so that human can read it
easily.
 HTTP request message consists of three parts: Request line, Header
line and Blank line
 Request line has three fields: Method, URL and Version Field.
 Method: There are five HTTP methods:
 GET: The GET method is used to requests an object from Web server,
with the requested object identified in the URL field.
 POST: POST method is used to send data (file, form data, etc.) to the
Web server.
 PUT: The PUT method is also used by applications that need to
upload objects to Web servers. (Modify the data on the server. )
 HEAD: Used to retrieve header information. It is used for debugging
purpose.
 DELETE: The DELETE method allows a user, or an application, to
delete an object on a Web server.
 URL: Specifies URL of the requested object
 Version: This field represents HTTP version, usually HTTP/1.1
 Header line:

 The header line Host: www.someschool.edu specifies the host on


which the object resides.
 By including the Connection: close, the browser is telling the server
that it doesn’t want to bother with persistent connections; it wants the
server to close the connection after sending the requested object.
 The User-agent: specifies the user agent, that is, the browser type
that is making the request to the server. Here the user agent is
Mozilla/5.0, a Firefox browser.

 The Accept-language: indicates that the user prefers to receive a


French version of the object, if such an object exists on the server;
otherwise, the server should send its default version.
HTTP Response Message:
 This response message could be the response to the request message
 The status line has three fields: the protocol version field, a status
code, and a corresponding status message.
 Version is HTTP/1.1 The status code and associated phrase indicate
the result of the request.
 Some common status codes and associated phrases include:
 200 OK: Request succeeded and the information is returned in the
response.
 301 Moved Permanently: Requested object has been permanently
moved.
 400 Bad Request: This is a generic error code indicating that the
request could not be understood by the server.
 404 Not Found: The requested document does not exist on this
server.
 505 HTTP Version Not Supported: The requested HTTP protocol
version is not supported by the server.
Header fields:
 The server uses the Connection: close to tell the client that it is going
to close the TCP connection after sending the message.

 The Date: header line indicates the time and date when the HTTP
response was created and sent by the server.

 The Server: header line indicates that the message was generated by
an Apache Web server; it is analogous to the User-agent.

 The Last-Modified: indicates the time and date when the object was
created or last modified.

 The Content-Length: indicates the number of bytes in the object


being sent.

 The Content-Type: indicates that the object in the entity body is


HTML text.
User-Server Interaction: Cookies
 HTTP uses cookies which allow sites to keep track of users.

 Although not all sites use cookies, most major portals, such as Yahoo,
e-commerce, such as Amazon sites make extensive use of cookies.

 The Cookie is a small message from a web server passed to the user’s
browser when you visit a website.

 Cookies are commonly used for information about user preferences


and other data on the website.

 Cookies help websites remember users and track their activities to


provide a personalised experience.

 It is also useful to remember the stateful information for the stateless


HTTP protocol.
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) back-end database at the Web site.
Web Caching (proxy server):
 A Web cache—also called 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.
 A user’s browser can be configured so that all of the user’s HTTP
requests are first directed to the Web cache.
 Web caching has seen deployment in the Internet for reasons it can
substantially reduce the response time for a client request.
Suppose browser is requesting the object
http://www.someschool.edu/campus.gif. Here is what happens:
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, if it has a copy of the object stored locally. If
it has, 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 and sends an HTTP request for
the object into origin server .
4. After receiving this request, the origin server sends the object within
an HTTP response to the Web cache.
5. 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.
Conditional GET:
 Although caching can reduce response times, it introduces a new
problem the copy of an object residing in the cache may be unfresh
(the object housed in the web server may have been modified)

 HTTP has a mechanism that allows a cache to verify that its objects
are up to date. This mechanism is called the conditional GET.

 To illustrate how the conditional GET operates, let’s see an example.

 First, on behalf of a requesting browser, a proxy cache sends a request


message to a web server:
GET /fruit/kiwi.gif HTTP/1.1
Host: www.exotiquecuisine.com
 Second, the web server sends a response message with the requested
object to the cache:
HTTP/1.1 200 OK
Date: Sat, 8 Oct 2011 15:39:29
Server: Apache/1.3.0 (Unix)
Last-Modified: Wed, 7 Sep 2011 09:23:24
Content-Type: image/gif
(data data data data ……………)

 The cache forwards the object to the requesting browser but also
caches the object locally. Importantly, the cache also stores the last-
modified date along with the object.
 Third, one week later, another browser requests the same object via
the cache, and the object is still in the cache. Since, this object may
have been modified at the web server in the past week, the cache
performs an up-to-date check by issuing a conditional GET.
Specifically, the cache sends:
GET /fruit/kiwi.gif HTTP/1.1
Host: www.exotiquecuisine.com
If-modified-since: Wed, 7 Sep 2011 09:23:2
 Not that the value of the If-modified-since: header line is exactly
equal to the value of the Last-Modified: header line that was sent by
the server one week ago.
 This conditional GET is telling the server to send the object only if the
object has been modified since the specified date.
 Suppose the object has not been modified since 7 Sep 2011 09:23:24.
Then, fourth, the web server sends a response message to the cache:
HTTP/1.1 304 Not Modified
Date: Sat, 15 Oct 2011 15:39:29
Server: Apache/1.3.0 (Unix)
(empty entity body)
 We see that in response to the conditional GET, the web server still
sends a response message but does not include the requested object in
the response message.
 Including the requested object would only waste bandwidth and
increase user-perceived response time, particularly if the object is
large.
Electronic Mail in the Internet
 It is the internet’s most important and utilized applications.

 As with ordinary postal mail, e-mail is an asynchronous


communication medium – people send and read messages when it is
convenient for them, without having to coordinate with other people’s
schedules.

 In contrast with postal mail, electronic mail is fast and inexpensive.

 Modern e-mail has many powerful features, including messages with


attachments, hyperlinks and embedded photos.
 E-mail has three major components: user agents, mail servers, and the
Simple Mail Transfer Protocol (SMTP).

 User agents allow users to read, reply to, forward, save, and compose
messages.

 Mail servers form the core of the e-mail infrastructure. Each recipient
has a mailbox located in one of the mail servers.

 SMTP is the principal application-layer protocol for Internet


electronic mail.

 It uses the reliable data transfer service of TCP to transfer mail from
the sender’s mail server to the recipient’s mail server.
SMTP
 SMTP – Simple Mail Transfer Protocol defined in RFC 5321, is at
the heart of internet electronic mail.

 SMTP transfers messages from sender’s mail servers to the recipient’s


mail servers.

 It restricts the body of all mail messages to simple 7-bit ASCII.

 This restriction made sense in early 1980s and no one was e-mailing
large attachments or large image, audio, or video files.

 But today, in the multimedia era, the 7-bit ASCII restriction is a bit of
a pain
 To illustrate the basic operation of SMTP, Suppose Alice wants to
send Bob a simple ASCII message.
1. Alice invokes her user agent for e-mail, provides Bob’s e-mail
address (for example, [email protected]), composes a message,
and instructs the user agent to send the message.
2. Alice’s user agent sends the message to her mail server, where it is
places in a message queue
3. The client side of SMTP, running on Alice’s mail server, sees the
message in the message queue. It opens a TCP connection to an
SMTP server, running on Bob’s mail server.
4. After some initial SMTP handshaking, the SMTP client sends Alice’s
message into the TCP connection.
5. At Bob’s mail server, the server side of SMTP receives the message.
Bob’s mail server then places the message in Bob’s mailbox.
6. Bob invokes his user agent to read the message at his convenience.
Comparison with HTTP
 Both protocols (HTTP and SMTP) are used to transfer files from one
host to another:

 HTTP transfers files (also called objects) from a Web server to a Web
client (typically a browser);

 SMTP transfers files (that is, e-mail messages) from one mail server
to another mail server.
SMTP HTTP

SMTP is used for mail services. HTTP is mainly used for data and
file transfer.
It uses port 25. It uses port 80.
It imposes a 7-bit ASCII restriction It does not impose a 7-bit ASCII
on the content to be transferred restriction. Can transfer
multimedia, hyperlinks, etc
SMTP transfers emails via Mail HTTP transfers files between the
Servers. Web server and the Web client.
SMTP is a persistent type of TCP It can use both Persistent and Non-
connection. persistent.
Has a smaller message size limit Has a larger message size limit
compared to HTTP. compared to SMTP.
Requires authentication for sending Does not require authentication for
emails. browsing web pages.
TCP UDP

Transmission control User Datagram


Protocol (TCP) Protocol(UDP)
Slower than UDP Faster than TCP
TCP offers error connection UDP doesn’t offer error
Guaranteed delivery connection &guaranteed
delivery
Connection oriented Protocol Connectionless Protocol
Generally use in webpages generally use in Audio&
video files
Mail Message Formats
• When an e-mail message is sent from one person to another, a header
containing peripheral information precedes the body of the message.
• This peripheral information is contained in a series of header lines,
which are defined in RFC 5322.
• The header lines and the body of the message are separated by a blank
line. Every header must have a From: header line and a To: header
line; a header may include a Subject: header line as well as other
optional header lines.
• A typical message header looks like this
Mail Access Protocols
 Mail Access Protocols SMTP protocol delivers the mail to the mail
server.

 In early 1990s this was the standard way of doing things.

 But today, mail access uses a client-server architecture – the typical


user reads e-mail on an office PC, a laptop, or a smartphone.

 To fetch the mail from mail server, receiver use mail access protocols.

 There are currently a number of popular mail access protocols,


including Post Office Protocol— Version 3 (POP3), Internet Mail
Access Protocol (IMAP), and HTTP.
POP3 (Post Office Protocol— Version 3 )
 POP3 is an extremely simple mail access protocol.
 POP3 begins when the user agent (the client) opens a TCP
connection to the mail server (the server) on port 110.
 With the TCP connection established, POP3 progresses through
three phases: authorization, transaction, and update.
 During the authorization phase, the user agent sends a username
and a password to authenticate the user.
 During the transaction phase, the user agent retrieves messages;
also during this phase, the user agent can mark messages for
deletion, remove deletion marks, and obtain mail statistics.
 The update phase occurs after the client has issued the quit
command, ending the POP3 session; at this time, the mail server
deletes the messages that were marked for deletion.
 In a POP3 transaction, the user agent issues commands, and the server
responds to each command with a reply.

 There are two possible responses: +OK used by the server to indicate
that the previous command was fine; and

 -ERR, used by the server to indicate that something was wrong with
the previous command.
Internet Mail Access Protocol (IMAP)
 With POP3, once user has downloaded his messages to the local
machine, he can create mail folders and move the downloaded
messages into the folders.
 User can then delete messages, move messages across folders, and
search for messages.
 But this poses a problem for the nomadic user(someone who lives by
traveling from place to place) who would prefer to maintain a folder
hierarchy on a remote server that can be accessed from any computer.

 This is not possible with POP3—the POP3 protocol does not provide
any means for a user to create remote folders and assign messages to
folders.
 To solve this and other problems, the IMAP protocol was invented.
Like POP3, IMAP is a mail access protocol. It has many more
features than POP3, but it is also significantly more complex.
 An IMAP server will associate each message with a folder; when a
message first arrives at the server, it is associated with the recipient’s
INBOX folder.
 The recipient can then move the message into a new, user-created
folder, read the message, delete the message, and so on.
Web-Based E-Mail

 More and more users today are sending and accessing their e-mail
through their Web browsers.

 Hotmail introduced web-based access in the mid 1990s. Now web-


based e-mail is also provided by Google, Yahoo!

 In this case user communicates with its remote mailbox via HTTP.

 When a sender, such as Alice, wants to send an e-mail message, the e-


mail message is sent from her browser to her mail server over HTTP
rather than over SMTP.

You might also like