You are on page 1of 26

Application Layer

Application Layer

Computer Communication & Networking CE - 402

Department of Computer Engineering, SSUET

CE - 402

Instructor: M. Rehan Rasheed

Network applications:
Process: program running
within a host.
within same host, two
processes communicate
using interprocess
communication (defined
by OS).
processes running in
different hosts
communicate with an
application-layer protocol

CE - 402

CC&N-CE-402

User agent: interfaces with


user above and
network below.
implements user interface
& application-level
protocol
Web: browser
E-mail: mail reader
streaming
audio/video: media
player

Instructor: M. Rehan Rasheed

Application Layer

Applications and application-layer protocols


Application: communicating,
distributed processes
e.g., e-mail, Web, P2P file
sharing, instant messaging
running in end systems
(hosts)
exchange messages to
implement application
Application-layer protocols
one piece of an app
define messages exchanged
by apps and actions taken
use communication services
provided by lower layer
protocols (TCP, UDP)

CE - 402

application
transport
network
data link
physical

application
transport
network
data link
physical

application
transport
network
data link
physical

Instructor: M. Rehan Rasheed

App-layer protocol defines

Types of messages
exchanged, eg, request &
response messages
Syntax of message types:
what fields in messages &
how fields are delineated
Semantics of the fields, ie,
meaning of information
in fields
Rules for when and how
processes send & respond
to messages

CE - 402

CC&N-CE-402

Public-domain protocols:
defined in RFCs
allows for
interoperability
eg, HTTP, SMTP
Proprietary protocols:
eg, KaZaA
THREE PARADIGMS
Client server
Peer-to-Peer
Hybrid

Instructor: M. Rehan Rasheed

Application Layer

Client-server paradigm
Typical network app has two
pieces: client and server
Client:

application
transport
network
data link
physical

initiates contact with server


(speaks first)
typically requests service from
server,
Web: client implemented in
browser; e-mail: in mail reader

Server:
provides requested service to client

request

reply
application
transport
network
data link
physical

e.g., Web server sends requested Web

page, mail server delivers e-mail


CE - 402

Instructor: M. Rehan Rasheed

Peer-to-Peer paradigm

Peers communicate with each other


Peers are desktop/laptops controlled by users
Communication is without passing through a dedicated
server
Examples: File distribution application (Bit Torrent,
Lime wire, eMule), Internet Telephony (Skype), IPTV
(PPLive)
Hybrid Applications are instant messaging services
(MSN, Yahoo)
Servers are used to track peer IP address and
messages are exchanged between users without
passing through intermediate servers

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

Application Layer

Internet apps: their protocols and transport


protocols
Application
e-mail
remote terminal access
Web
file transfer
streaming multimedia
remote file server
Internet telephony

Application
layer protocol

Underlying
transport protocol

smtp
telnet
http
ftp
proprietary
(e.g. RealNetworks)
NSF
proprietary
(e.g., Vocaltec)

TCP
TCP
TCP
TCP
TCP or UDP

CE - 402

TCP or UDP
typically UDP

Instructor: M. Rehan Rasheed

WWW: the http protocol


http: hypertext transfer
protocol

WWWs application layer


protocol
client/server model
client: browser that
requests, receives,
displays WWW objects
server: WWW server
sends objects in response
to requests

CE - 402

CC&N-CE-402

PC running
Explorer

Server
running
NCSA Web
server
Mac running
Navigator

Instructor: M. Rehan Rasheed

Application Layer

WWW: the http protocol

The WWW today is a distributed client/server service, in


which a client using a browser can access a service using a
server.
However, the service provided is distributed over many
locations called sites.
Each site holds one or more documents, referred to as
Web pages.
The request, among other information, includes the
address of the site and the Web page, called the URL

CE - 402

Instructor: M. Rehan Rasheed

Architecture of WWW

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

10

Application Layer

Client (Browser)

Each browser usually consists of three parts: a controller, client protocol, and
interpreters.
The controller receives input from the keyboard or the mouse and uses the
client programs to access the document.
After the document has been accessed, the controller uses one of the
interpreters to display the document on the screen.
The client protocol can be one of the protocols described previously such as
FTP or HTTP.
The interpreter can be HTML, Java, or JavaScript, depending on the type of
document.

CE - 402

Instructor: M. Rehan Rasheed

11

URL

To facilitate the access of documents distributed


throughout the world, HTTP uses locators.
The uniform resource locator (URL) is a standard for
specifying any kind of information on the Internet.
The URL defines four things: protocol, host computer,
port, and path

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

12

Application Layer

Cookies

A cookie, also known as an HTTP cookie, web cookie, or


browser cookie, is a small piece of data sent from a website and
stored in a user's web browser while the user is browsing that
website.
Every time the user loads the website, the browser sends the
cookie back to the server to notify the website of the user's
previous activity.
Cookies were designed to be a reliable mechanism for websites
to remember stateful information (such as items in a shopping
cart) or to record the user's browsing activity (including clicking
particular buttons, logging in, or recording which pages were
visited by the user as far back as months or years ago).

CE - 402

Instructor: M. Rehan Rasheed

13

Cookies

The World Wide Web was originally designed as a stateless


entity. A client sends a request; a server responds. Their
relationship is over.
The original design of WWW, retrieving publicly available
documents, exactly fits this purpose.
Today the Web has other functions; some are listed here.
1.
2.

3.

4.

Some websites need to allow access to registered clients only.


Websites are being used as electronic stores that allow users to browse
through the store, select wanted items, put them in an electronic cart,
and pay at the end with a credit card.
Some websites are used as portals: the user selects the Web pages he
wants to see.
Some websites are just advertising.

For these purposes, the cookie mechanism was devised


CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

14

Application Layer

WEB DOCUMENTS

The documents in the WWW can be grouped into three


broad categories: static, dynamic, and active.

The category is based on the time at which the contents of


the document are determined.

CE - 402

Instructor: M. Rehan Rasheed

15

Static document
When a client accesses the document, a copy of the document is
sent. The user can then use a browsing program to display the
document

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

16

Application Layer

Dynamic document using CGI

A dynamic document is created by a Web server whenever a


browser requests the document.
When a request arrives, the Web server runs an application
program or a script that creates the dynamic document. The
server returns the output of the program or script as a response
to the browser that requested the document.

CE - 402

Instructor: M. Rehan Rasheed

17

Dynamic document using server-site script

Dynamic documents are sometimes referred to as server-site


dynamic documents.
CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

18

Application Layer

Active document using Java applet

Active document using client-site script

Active documents are


sometimes referred to as
client-site dynamic
documents.

CE - 402

Instructor: M. Rehan Rasheed

19

HTTP

The Hypertext Transfer Protocol (HTTP) is a protocol used


mainly to access data on the World Wide Web. HTTP functions
as a combination of FTP and SMTP.
It is similar to FTP because it transfers files and uses the
services of TCP.
However, it is much simpler than FTP because it uses only one
TCP connection. There is no separate control connection; only
data are transferred between the client and the server.

HTTP uses the services of TCP on well-known port 80.

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

20

10

Application Layer

Request and response messages

CE - 402

Instructor: M. Rehan Rasheed

21

The http protocol: more


http: TCP transport service:
client initiates TCP connection
(creates socket) to server, port 80
server accepts TCP connection
from client
http messages (application-layer
protocol messages) exchanged
between browser (http client) and
WWW server (http server)
TCP connection closed

CE - 402

CC&N-CE-402

http is stateless
server
maintains
no
information about past client
requests
so that the communication
consists of independent pairs
of request and response
Protocols that maintain state
are complex!

Instructor: M. Rehan Rasheed

22

11

Application Layer

http example
Suppose user enters URL

(contains text, references

www.SSUET.edu/CEDt/home.index

to 10 jpeg images)

1a. http client initiates TCP


connection to http server
(process) at www.SSUET.edu.
Port 80 is default for http server.

2. http client sends http request


message (containing URL) into
TCP connection socket

time
CE - 402

1b. http server at host

www.SSUET.edu waiting for


TCP connection at port 80.
accepts connection, notifying
client

3. http server receives request

message, forms response


message containing requested
object (CED/home.index),
sends message into socket

Instructor: M. Rehan Rasheed

23

http example (cont.)


4. http server closes TCP

5. http client receives response

connection.

message containing html file,


displays html. Parsing html file,
finds 10 referenced jpeg
objects

6. Steps 1-5 repeated for each

time

CE - 402

CC&N-CE-402

of 10 jpeg objects

Instructor: M. Rehan Rasheed

24

12

Application Layer

HTTP persistent connection


HTTP persistent connection, also called HTTP keep-alive, or
HTTP connection reuse, is the idea of using a single TCP
connection to send and receive multiple HTTP
requests/responses, as opposed to opening a new connection
for every single request/response pair

HTTP 1.1

In HTTP 1.1, all connections are considered persistent unless


declared otherwise. The HTTP persistent connections do not use
separate keepalive messages, they just allow multiple requests
to use a single connection.

CE - 402

Instructor: M. Rehan Rasheed

25

Advantages Persistent connection

Lower CPU and memory usage (because fewer connections are


open simultaneously).

Enables HTTP pipelining of requests and responses.

Reduced network congestion (fewer TCP connections).

Reduced latency in subsequent requests (no handshaking).

Errors can be reported without the penalty of closing the TCP


connection.

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

26

13

Application Layer

Persistent V/s Non persistent

non-persistent
connection: one object
in each TCP
connection
some browsers
create multiple
TCP connections
simultaneously one per object
persistent connection:
multiple objects
transferred within one
TCP connection

CE - 402

Instructor: M. Rehan Rasheed

27

http message format: request

two types of http messages: request, response


http request message:

ASCII (human-readable format)

request line
(GET, POST,
HEAD commands)

GET /somedir/page.html HTTP/1.1


Connection: close
header User-agent: Mozilla/4.0
lines Accept: text/html, image/gif,image/jpeg
Accept-language:fr
Carriage return,
line feed
(extra carriage return, line feed)
indicates end
of message

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

28

14

Application Layer

http request message: general format

CE - 402

Instructor: M. Rehan Rasheed

29

http message format: reply


status line
(protocol
status code
status phrase)
header
lines

HTTP/1.1 200 OK
Connection: close
Date: Thu, 06 Aug 2011 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 2011 ...
Content-Length: 6821
Content-Type: text/html
data data data data data ...

data, e.g.,
requested
html file

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

30

15

Application Layer

http reply status codes


In first line in server->client response message.
A few sample codes:

200 OK

request succeeded, requested object later in this message

301 Moved Permanently

requested object moved, new location specified later in this


message (Location:)

400 Bad Request

request message not understood by server

404 Not Found

requested document not found on this server

505 HTTP Version Not Supported


CE - 402

Instructor: M. Rehan Rasheed

31

User-server interaction: authentication

Authentication goal: control


access to server documents
stateless: client must present
authorization in each request
authorization: typically name,
password
authorization: header line in
request
if no authorization presented,
server refuses access, sends
WWW authenticate:
header line in response

client

server

usual http request msg


401: authorization req.
WWW authenticate:
usual http request msg
+ Authorization:line
usual http response msg
usual http request msg
+ Authorization:line
usual http response msg

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

time
32

16

Application Layer

User-server interaction: conditional GET


server

client

Goal: dont send object if


client has up-to-date stored
(cached) version
client: specify date of cached
copy in http request

http request msg


If-modified-since:
<date>

http response
HTTP/1.0
304 Not Modified

object
not
modified

If-modified-since:
<date>

server: response contains no


object if cached copy up-todate:
HTTP/1.0 304 Not
Modified

http request msg


If-modified-since:
<date>

http response

object
modified

HTTP/1.1 200 OK

<data>

CE - 402

33

Instructor: M. Rehan Rasheed

Web Caches (proxy server)


Goal: satisfy client request without involving origin server

user sets browser:


WWW accesses via
web cache
client sends all http
requests to web cache

CE - 402

CC&N-CE-402

origin
server

client

if object at web cache,


web cache immediately
returns object in http
response
else requests object
from origin server, then
returns http response to
client

client

Instructor: M. Rehan Rasheed

Proxy
server

origin
server
34

17

Application Layer

Why WWW Caching?


Assume: cache is close to
client (e.g., in same
network)
smaller response time:
cache closer to client
decrease traffic to distant
servers

link out of institutional/local


ISP network often
bottleneck

origin
servers
public
Internet

1.5 Mbps
access link
institutional
network

10 Mbps LAN

institutional
cache
CE - 402

Instructor: M. Rehan Rasheed

35

ftp: the file transfer protocol

user
at host

CE - 402

CC&N-CE-402

FTP
FTP file transfer
user
client
interface
local file
system

FTP
server
remote file
system

transfer file to/from remote host


client/server model
client: side that initiates transfer (either to/from remote)
server: remote host
ftp server: port 21

Instructor: M. Rehan Rasheed

36

18

Application Layer

ftp: separate control, data connections

ftp client contacts ftp server at


port 21, specifying TCP as
transport protocol
two parallel TCP connections
opened:
control: exchange
commands, responses
between client, server.
out of band control
data: file data to/from server
ftp server maintains state:
current directory, earlier
authentication

CE - 402

TCP control connection


port 21
TCP data connection

FTP port 20
client

Instructor: M. Rehan Rasheed

FTP
server

37

ftp commands, responses


Sample commands:
sent as ASCII text over control
channel
USER username
PASS password

LIST return list of files in


current directory

RETR filename retrieves


(gets) file

STOR filename stores (puts)


file onto remote host

CE - 402

CC&N-CE-402

Sample return codes

status code and phrase (as in


http)
331 Username OK,
password required
125 data connection
already open; transfer
starting
425 Cant open data
connection
452 Error writing file

Instructor: M. Rehan Rasheed

38

19

Application Layer

Electronic Mail

outgoing
message queue

Three major components:

user agents
mail servers
simple mail transfer protocol:
smtp

User Agent
a.k.a. mail reader
composing, editing, reading
mail messages
e.g., Microsoft Outlook,
Pegasus Mail,Gmail, Yahoo
outgoing, incoming messages
stored on server
CE - 402

user mailbox

user
agent
mail
server

SMTP
SMTP
mail
server

user
agent

user
agent
mail
server

SMTP

user
agent

user
agent

user
agent

Instructor: M. Rehan Rasheed

39

Electronic Mail: mail servers


user
agent

Mail Servers

mailbox contains incoming


messages (yet to be read) for user
message queue of outgoing (to be
sent) mail messages
smtp protocol between mail server
to send email messages
client: sending mail server
server: receiving mail server

mail
server

SMTP
SMTP
mail
server

user
agent
CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

SMTP

user
agent
mail
server

user
agent

user
agent

user
agent

40

20

Application Layer

Electronic Mail: Smtp

uses tcp to reliably transfer email msg from client


to server, port 25
direct transfer: sending server to receiving server
three phases of transfer
handshaking (greeting)
transfer
closure
command/response interaction
commands: ASCI text
response: status code and phrase

CE - 402

Instructor: M. Rehan Rasheed

41

Sample smtp interaction


S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
S:
C:
S:
CE - 402

CC&N-CE-402

220 SSUET.edu
HELO yahoo.com
250 Hello yahoo.com, pleased to meet you
MAIL FROM: <amir@yahoo.com >
250 amir@yahoo.com ... Sender ok
RCPT TO: <asad@SSUET.edu>
250 asad@SSUET.edu ... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Do you like ketchup?
How about pickles?
.
250 Message accepted for delivery
QUIT
221 SSUET.edu closing connection
Instructor: M. Rehan Rasheed

42

21

Application Layer

Smtp: http
Comparison with http

http: pull
email: push
both have ASCII command/response interaction, status codes
http: each object encapsulated in its own response (if v.1.0 or so
specified in 1.1)
smtp: multiple message parts sent in one connection (multipart
mess)

CE - 402

Instructor: M. Rehan Rasheed

43

Message format: multimedia extensions

MIME: multimedia mail extension,


additional lines in msg header declare MIME content type

MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
CE - 402

CC&N-CE-402

From: amir@yahoo.com
To: asad@SSUET.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
.

Instructor: M. Rehan Rasheed

44

22

Application Layer

Mail access protocols


user
agent

SMTP

SMTP

senders mail
server

POP3 or
IMAP

receivers mail
server
POP

SMTP: delivery/storage to receivers server


Mail access protocol: retrieval from server
POP: Post Office Protocol

authorization (agent <-->server) and


download
IMAP: Internet Mail Access Protocol

more features (more complex)

manipulation of stored msgs on


server

CE - 402

user
agent

IMAP

Relatively
straightforward

Slower but more


redundant

Faster (sends your


e-mails and gets emails from you)

Keeps a copy of
everything you do on
the server

The downside is that The downside is that it


takes up more space
if you lose e-mails
on your computer
you have lost them
forever (unless you
have saved a copy
on the server)

Instructor: M. Rehan Rasheed

45

P2P file sharing


Example
Alice runs P2P client application
on her notebook computer
Intermittently connects to
Internet; gets new IP address for
each connection
Asks for XYZ
Application displays other peers
that have copy of XYZ.

CE - 402

CC&N-CE-402

Alice chooses one of the peers,


Bob.
File is copied from Bobs PC to
Alices notebook: HTTP
While Alice downloads, other
users uploading from Alice.
Alices peer is both a Web client
and a transient Web server.
All peers are servers = highly
scalable!

Instructor: M. Rehan Rasheed

46

23

Application Layer

P2P: centralized directory


original Napster design
1) when peer connects, it
informs central server:

Bob
centralized
directory server

1
peers

IP address
content

2) Alice queries for XYZ


3) Alice requests file from
Bob

1
2

Alice

CE - 402

Instructor: M. Rehan Rasheed

47

P2P: problems with centralized directory

Single point of failure


Performance bottleneck
Copyright violation

CE - 402

CC&N-CE-402

file transfer is
decentralized, but
locating content is
highly decentralized

Instructor: M. Rehan Rasheed

48

24

Application Layer

P2P: decentralized directory

Each peer is either a group


leader or assigned to a
group leader.
Group leader tracks the
content in all its children.
Peer queries group leader;
group leader may query
other group leaders.

ordinary peer
group-leader peer
neighoring relationships
in overlay network

CE - 402

Instructor: M. Rehan Rasheed

49

More about decentralized directory


overlay network
peers are nodes
edges between peers and their
group leaders
edges between some pairs of
group leaders
virtual neighbors
bootstrap node
connecting peer is either
assigned to a group leader or
designated as leader

CE - 402

CC&N-CE-402

advantages of approach
no centralized directory server

location service distributed


over peers
more difficult to shut down

disadvantages of approach
bootstrap node needed
group leaders can get
overloaded

Instructor: M. Rehan Rasheed

50

25

Application Layer

P2P: Query flooding

Gnutella
no hierarchy
use bootstrap node to learn
about others
join message

Send query to neighbors


Neighbors forward query
If queried peer has object,
it sends message back to
querying peer

join

CE - 402

Instructor: M. Rehan Rasheed

51

Skype

Skype is a peer-to-peer VoIP client


developed in 2003 by the
organization that created Kazaa
Skype uses an overlay peer-to-peer
network
An ordinary host must connect to a
super node and must authenticate
itself with the Skype login server
User names, passwords and buddy
list are stored at the login server
It uses TCP for signaling and both
UDP and TCP for transporting
media traffic

CE - 402

CC&N-CE-402

Instructor: M. Rehan Rasheed

52

26

You might also like