You are on page 1of 41

Lecture 7:

Application Layer
HEDSPI Project
Hanoi University of Technology
by
Ngo Hong Son

1
Overview
 Last weeks : Transport Layer
 Principles of transport layer
 TCP and UDP
 Concept of congestion and flow control
 Today: Application Layer
 Principles of the application layer
 Case study: HTTP, Mail, FTP…

2
Basic concepts

3
Remind of protocol stack
Application Supporting network applications
(HTTP, Mail, …)

Transport Transferring data of application processes


(UDP, TCP …)

Network
Routing and forwarding packet among
(IP, ICMP…) networks

Datalink Dealing the communication between


(Ethernet, ADSL…) adjacent computers and devices

Physical Transmitting and receiving raw bits on


(bits…) physical media
4
Network applications and services
MUSIC ONLINE
VoIP
GAME CHAT VoD
ON LINE e-Office
SMS e-BANK
MAIL
SCHOOL
WEB
ON THE YOUTUBE
INTERNET VIDEO
CONFERENCE FTP
EBAY
GOOGLE SKYPE
TELNET
SSH

NEWS E-COMMERCE GRID


BITTORENT
5
e-Goverment
Application and application-layer
protocol
 Application protocol application
transport
 Rule of communication network
data link
 Use services provided by physical

transport layer protocols (e.g.


TCP/UDP…)
 Application:
 Processes that communicate
over Internet (exchange
messages)
 Run in end-systems
application
 Implement app. protocols to transport
provide services network
data link
application
 For examples: physical
transport
network
 Web (HTTP) data link
physical
 Mail (SMTP/POP/IMAP) …
6
Elements of network application
 Application program
 User agent:
 Interface for user to use application,
 e.g. a web browser (Firefox, IE), an email software
(Thunderbird, Outlook,..)
 Server program
 Provide service to user agent

 Processes: running program on Operating System


 How do processes communicate?
 On the same host: by IPC (inter-process communication)
 Among different hosts: by socket

7
Processes communication over
Internet
 Socket: an interface between
application process and host or host or
server server
transport layer
 Socket is identified by controlled by
 Port number app developer
process process
 IP address socket
socket
 Type of transport service (TCP transport
transport
or UDP) layer Internet layer
 Socket API (Application services services

Programming Interface): Allow


to select TCP or UDP, change controlled
parameters… by OS

8
Service communication model
 Client-server
 Peer-to-Peer (P2P)
 Hybrid

9
Client-Server
 Clients
client  Send request to server
 Do not connect directly
client to other clients
 Servers
 Wait request from server
client
Server  Always-on, always-
connected computer
 May have several ones
for scalability
client
 e.g. Web, Mail, …
10
Pure P2P
Peer Peer
 No central server
 Every computer (peer) has the
same role
 Arbitrary peers may connect
Peer directly
Peer  May occasionally leave-off the
network
 E.g. Gnutella

Peer Peer

11
Hybrid P2P and Client-Server
Client
 Central server are used
to managed client (Log-in
info., searching info., …)
 Clients can connect
directly after logging in.
Server
 E.g. Skype
 Skype servers manage
user accounts, log-in
session
Client Client  One connected, peers can
communicate an VoIP
session directly
Client-Server Comm.
12
P2P Comm.
Case study

13
HTTP and Web
Web clients
 WWW: World Wide Web
 Share HTML (HyperText
Markup Language) documents htt
over Internet IE p req
htt ue Web
p res st
 HTTP: HyperText Transfer po server
ns
Protocol e
 Client/Server model
 Client requests web objects and Firefox
display them on a web browser est
u
 Server: Receive request and r eq n se
p po
htt s
send response to client p re
ht t

14
Navigator
How does HTTP work?
 Server opens a listening TCP socket at port 80
(default)
 Client initializes a TCP connection to server
 Server accepts connection request
 Client and Server exchange HTTP messages
(Application level protocol)
 HTTP Request
 HTTP Response
 TCP connection closed

15
HTTP request message
 ASCII format (can be read as text)

request line
(GET, POST, GET /dccn/index.html HTTP/1.1
HEAD commands) Host: www.it-hut.edu.vn
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:en-us

CR, LF
(extra carriage return, line feed)
indicates end
of message
16
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection close
Date: Tue, 16 Mar 2008 12:00:15 GMT
header Server: Apache/1.3.0 (Unix)
lines Last-Modified: Mon, 15 Mar 2008 …...
Content-Length: 8990
Content-Type: text/html

data, e.g., data data data data data ...


requested
HTML file

17
HTTP connections
Non-persistent HTTP Persistent HTTP
 At most one object is sent  Multiple objects can be sent
over a TCP connection. over single TCP connection
 HTTP/1.0 uses between client and server.
nonpersistent HTTP  HTTP/1.1 uses persistent
 HTTP 1.0: RFC 1945 connections in default mode
 HTTP 1.1: RFC 2068

18
Non-Persistent HTTP in action
Web client Web server

Init TCP connection TCP C


o nn . Req.
Accept TCP connection

OK, send HTTP request GET /index


.h tml Send HTTP response: index.html
html Close TCP connection
index.
Parse index.html: has 10 TCP C
onn . Req.
reference to 10 images

ted Accept TCP connection


Repeat above steps 10 Accep
times!
GET im
g1.jpg
Send images 1
p g
img1.j Close TCP connection
2xRTT 19

Time Time
Persistent HTTP in action
Web client Web server

Init TCP connection TCP C


o nn . Req.
Accept TCP connection
ted
Accep

OK, send HTTP request GET /index


.h tml
Send HTTP
html
Parse index.html: has 10 index. response: index.html
reference to 10 images
GET…
request images 1
pg Send images 1
img1.j

request images 2 GET…

Send images 2

Stop-and- Pipeline
request images 10 wait! 20

Time Time
Persistent HTTP with pipeline
Web client Web server

Init TCP connection TCP C


o nn . Req.
Accept TCP connection
ted
Accep

OK, send HTTP request GET /index


.h tml
Send HTTP
html
Parse index.html: has 10 index. response: index.html
reference to 10 images
GET…
request images 1 -10
Send images 1-10

21

Time Time
Request message: Method types
HTTP/1.0 HTTP/1.1
 GET  GET, POST, HEAD

 POST  PUT

 HEAD  uploads file in entity body to


 asks server to leave path specified in URL field
requested object out of  DELETE
response  deletes file specified in the
URL field

Note: Input can be uploaded by GET method in URL field of


request line:
http://www.google.com/search?q=computer+network&flags=68&num=10
22
Response message: status codes
In first line of the response message. E.g:
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

23
Caching
 “Cache”: Buffer memory www.xyz.com/index.htm

 You may know the “cache”


in a computer
 L1 cache, L2 cache
 What is “cache miss”,
“cache hit”
 Consider the following case:
 An institution has one link
to Internet
 All the traffic to Internet
pass through this link
 Many Web users can
access to the same content
on the same server

24
Solution: Web caches (proxy server)

 User sets browser:


Web accesses via Web
server
cache
 browser sends all HT Proxy
TP
req server q uest
HTTP requests to HT
client TP ue st T TP re
o n se
H p
proxy res
pon P r es
se H TT
st
 Hit: Proxy returns r eq
u e
P nse
object HT
T
r es
p o
TP
 Miss: Proxy requests HT

object from origin client


server, then returns
object to client
25
Web caches
 Proxy: Being client and also server
 Typically used by ISP (campus, company,
residential ISP)
 Effect of web proxy
 Reduce Internet traffic on the access link
 May reduce response time, but what happen is
case of
 cache hit
 cache miss
 proxy is overloaded
 dynamic web page? 26
Dealing with dynamic web:
Conditional GET
proxy server
 Goal: don’t send object if
cache has up-to-date HTTP request msg
cached version If-modified-since: <date>
object
 cache: specify date of not
cached copy in HTTP HTTP response modified
request HTTP/1.0
304 Not Modified
If-modified-since: <date>
 server: response contains
HTTP request msg
no object if cached copy is If-modified-since: <date>
up-to-date: object
HTTP/1.0 304 Not Modified modified
HTTP response
HTTP/1.0 200 OK
<data>
27
Local cache
 Web cache in the cache on the local host, not
on a proxy server
 Local cache can be used for:
 Offline web-browsing
 Browse web pages more efficiently: if the content
of a web pages does not change, so we can use
the content in the cache.

28
Electronic Mail
 MUA (Mail User Agent)  Protocol for sending mail:
 Read email from server, STMP-Simple Mail Transfer
 e.g. Outlook, Thunderbird… Protocol
 MTA (Mail Transfer Agent):  Protocol for accessing mail
 Mail boxes for incoming mails of  POP – Post Office Protocol
users  IMAP – Internet Mail Access
 Message queue for outgoing mails Protocol
 e.g. Sendmail, MS Exchange…

IMAP IMAP
mail mail
POP POP
user server SMTP server user
agent agent
SMTP SMTP 29

Mail box Message queue


SMTP
 RFC 2821
 TCP, port 25: transfer email message from client
to server and from server to server.
 command/response interaction
 commands: ASCII text

 response: status code and phrase

30
Mail access protocols
SMTP SMTP access user
user
agent protocol agent

sender’s mail receiver’s mail


server server

 POP: Post Office Protocol [RFC 1939]


 Authentication (agent <-->server) and download

 IMAP: Internet Mail Access Protocol [RFC 1730]


 more features (more complex)

 manipulation of stored msgs on server

31
Web Mail service
 Use Web browser as an MUA
 HTTP is used between MUA and MTA
 Mails are also kept on server
 E.g.
 Gmail,
 Hotmail,
 Yahoo! Mail, etc.
 Nowadays, many server allows web interface to mail
services
 http://mail.hut.edu.vn
 http://mail.fit.hut.edu.vn
32
Mail message format
SMTP: protocol for exchanging
email msgs
header
blank
RFC 822: standard for text line
message format:
 header lines, e.g.,
body
 To:
 From:
 Subject:
 body
 the “message”, ASCII
characters only

33
Message format: multimedia extensions
 MIME: multimedia mail extension, RFC 2045, 2056
 additional lines in msg header declare MIME content
type

From: alice@crepes.fr
MIME version To: bob@hamburger.edu
Subject: Picture of yummy crepe.
method used MIME-Version: 1.0
to encode data Content-Transfer-Encoding: base64
Content-Type: image/jpeg
multimedia data
type, subtype, base64 encoded data .....
parameter declaration .........................
......base64 encoded data
encoded data

34
File Transfer Protocol

35
FTP: File Transfer Protocol

TCP control
connection, port 21
user FTP FTP
interface client server
TCP data
user connection, port 20

local file system remote file system

 Client-server model  Out-of-band control:


 FTP command : port 21
 File transfer between two
 Data: port 20
hosts
 Need user to log-in before data
 RFC 959
transfer
 Use TCP, port 20, 21  Some servers allow anonymous
user 36
FTP commands, responses
Sample commands: Sample return codes
 USER username  331 Username OK,
 PASS password password required
 LIST return list of file in
 125 data connection
current directory already open; transfer
starting
 RETR filename retrieves  425 Can’t open data
(gets) file
connection
 STOR filename stores  452 Error writing file
(puts) file onto remote host

37
FTP client
Command line

C:\Documents and Settings\hongson>ftp


ftp> ?
Commands may be abbreviated. Commands are:

! delete literal prompt send


? debug ls put status
append dir mdelete pwd trace
ascii disconnect mdir quit type
bell get mget quote user
binary glob mkdir recv verbose
bye hash mls remotehelp
cd help mput rename
close lcd open rmdir

GUI FTP clients: IE, Firefox, GFTP, …. 38


Summary of application layer
 Application service model
 Client-server vs. P2P
 Typical applications and protocols
 HTTP
 Mail
 FTP
 You should read more about
 P2P file sharing
 ……
 Socket API
39
Next week: Data-link Layer

40
Acknowledgement
 This course materials contains charts and texts
provided by Keio University, Japan
 Some materials from the textbook “Computer
Network, a top down approach” J.F Kurose and
K.W. Ross

41

You might also like