You are on page 1of 29

Computer and

Communication Networks
EE-357 -TE-54
By Dr Mir Yasir Umair
Assistant Professor, MCS, NUST
Application Layer
Lecture 02
Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
o app architectures
with UDP and TCP
o app requirements

2.2 Web and HTTP


2.3 FTP
2.4 electronic mail
o SMTP, POP3, IMAP

2.5 DNS

Application Layer
World Wide Web
The World Wide Web (WWW) is an information space where
documents and other web resources are identified by URLs
(Uniform Resource Locator), interlinked by hypertext links, and can
be accessed via the Internet.

Web standards
• Representation:
o HyperText Markup Language (HTML)
• Transfer:
o HyperText Transfer Protocol (HTTP)
Web and HTTP
First, a review…
• web page consists of objects
• object can be HTML file, JPEG image, Java applet, audio
file,…
• web page consists of base HTML-file which includes
several referenced objects
• each object is addressable by a URL, e.g.,
www.someschool.edu/someDept/pic.gif

host name path name

Application Layer
HTTP overview
HTTP: hypertext
transfer protocol
• Web’s application
layer protocol PC running
• client/server model Firefox browser
o client: browser that
requests, receives,
(using HTTP
protocol) and
“displays” Web server
objects running
o server: Web server Apache Web
sends (using HTTP server
protocol) objects in
response to iphone running
requests Safari browser

Application Layer
HTTP overview (continued)
uses TCP: HTTP is
• client initiates TCP
“stateless”
• server maintains no
connection (creates information about
socket) to server, port 80 past client requests
• server accepts TCP
connection from client aside
• HTTP messages protocols that maintain
(application-layer “state” are complex!
protocol messages) ❖ past history (state) must be
maintained
exchanged between ❖ if server/client crashes, their
browser (HTTP client) and views of “state” may be
Web server (HTTP server) inconsistent, must be
• TCP connection closed reconciled

Application Layer
HTTP connections
non-persistent HTTP persistent HTTP
• at most one object sent • multiple objects
over TCP connection can be sent over
o connection then closed single TCP
• downloading multiple connection
objects required multiple between client,
connections server

Application Layer
Non-persistent HTTP
suppose user enters URL: (contains text,
www.someSchool.edu/someDepartment/home.index references to 10
jpeg images)

1a. HTTP client initiates TCP


connection to HTTP server 1b. HTTP server at host
(process) at www.someSchool.edu waiting
www.someSchool.edu on for TCP connection at port 80.
port 80 “accepts” connection, notifying
2. HTTP client sends HTTP request client
message (containing URL) into
TCP connection socket. 3. HTTP server receives request
Message indicates that client message, forms response
wants object message containing requested
someDepartment/home.index object, and sends message into
its socket
time
Application Layer
Non-persistent HTTP (cont.)
4. HTTP server closes TCP
connection.
5. HTTP client receives response
message containing html file,
displays html. Parsing html
file, finds 10 referenced jpeg
objects
time
6. Steps 1-5 repeated for each of
10 jpeg objects

Application Layer
Non-persistent HTTP: response time
RTT (definition): time for a
small packet to travel
from client to server and
back
initiate TCP
HTTP response time: connection
• one RTT to initiate TCP RTT
connection request
file
• one RTT for HTTP request time to
and first few bytes of HTTP RTT transmit
response to return file
file
• file transmission time received
• non-persistent HTTP
response time = time time
2RTT+ file transmission time

Application Layer
Persistent HTTP

non-persistent HTTP persistent HTTP:


issues: • server leaves
connection open after
• requires 2 RTTs per sending response
object • subsequent HTTP
• OS overhead for each messages between
TCP connection same client/server sent
over open connection
• browsers often open • client sends requests as
parallel TCP soon as it encounters a
connections to fetch referenced object
referenced objects • as little as one RTT for all
the referenced objects

Application Layer
HTTP Request Message
Reques Method Directory Version
t Line
Get /dir/page.html HTTP/1.1
Host: www.nust.edu.pk Domain
Header Line

User-agent: Mozilla/4.0 Browser Type making


request
Accept: text/html, image/gif, image/jpeg Media Type
Accept-Language: fr User prefers French version of
object
Connection: close Close connection after
sending requested objects
Uploading form input
POST method:
• web page often
includes form input
• input is uploaded to
server in entity body
URL method:
• uses GET method
• input is uploaded in
URL field of request
line: www.somesite.com/animalsearch?monkeys&banana

Application Layer
Method types
HTTP/1.0: HTTP/1.1:
• GET • GET, POST, HEAD
• POST • PUT
• HEAD o For Publishing as a
o For developers – tool
for debugging a • DELETE
website o deletes file
specified in the URL
field

Application Layer
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK\r\n
status phrase) 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
header ETag: "17dc6-a5c-bf716880"\r\n
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
Application Layer
HTTP response status codes
❖ status code appears in 1st line in server-to-
client response message.
❖ some sample codes:
200 OK
o request succeeded, requested object later in this msg
301 Moved Permanently
o requested object moved, new location specified later in
this msg (Location:)
400 Bad Request
o request msg not understood by server
404 Not Found
o requested document not found on this server
505 HTTP Version Not Supported
Application Layer
User-server state:
example:
cookies
many Web sites use
cookies • Susan always access
four components: Internet from PC
1) cookie header line • visits specific e-
of HTTP response commerce site for first
message
time
2) cookie header line
in next HTTP request • when initial HTTP
message requests arrives at site,
3) cookie file kept on site creates:
user’s host, o unique ID
managed by user’s
browser o entry in backend
4) back-end database database for ID
at Web site

Application Layer
Cookies: keeping “state” (cont.)
client server

ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action

one week later:


access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
specific
usual http response msg action
Application Layer
Cookies (continued)
aside
what cookies can cookies and privacy:
be used for: ❖ cookies permit sites to
• authorization learn a lot about you
• shopping carts ❖ you may supply name and
• recommendations e-mail to sites
• user session state
(Web e-mail)

how to keep “state”:


❖ protocol endpoints: maintain state at
sender/receiver over multiple
transactions
❖ cookies: http messages carry state

Application Layer
Web caches (proxy server)
goal: satisfy client request without involving origin server
• user sets browser: Web
accesses via cache
• browser sends all HTTP proxy
requests to cache server
client
o object in cache: origin
cache returns object server

o else cache requests


object from origin
server, then returns
object to client client origin
server

Application Layer
More about Web caching
• cache acts as why Web caching?
both client and • reduce response time
for client request
server • reduce traffic on an
o server for original institution’s access
requesting client link
o client to origin server • Internet dense with
• typically cache is caches: enables
installed by ISP “poor” content
providers to
(university, effectively deliver
company, content (so too does
P2P file sharing)
residential ISP)
Application Layer
Caching example:

Application Layer
Caching example: faster access link

Application Layer
Caching example: install local cache

Application Layer
Conditional GET
client server
• Goal: don’t send
object if cache has up-
to-date cached version HTTP request msg
o no object transmission If-modified-since: <date> object
delay not
o lower link utilization HTTP response
modified
• cache: specify date of HTTP/1.0
before
cached copy in HTTP 304 Not Modified
<date>
request
If-modified-since:
<date>
• server: response HTTP request msg
contains no object if If-modified-since: <date> object
cached copy is up-to- modified
date: HTTP response after
HTTP/1.0 304 Not HTTP/1.0 200 OK <date>
Modified
<data>
Application Layer
Example

Application Layer
Thank you

Application Layer
Application Layer

You might also like