Computer Networks
Lecture 3: application layer
Prof. Younghee Lee
* Some part of this teaching materials are prepared referencing the
lecture note made by F. Kurose, Keith W. Ross(U. of Massachusetts)
1 1
Prof. Younghee Lee
Some network apps
E-mail Internet telephone
Web Real-time video
Instant messaging conference
Remote login Massive parallel
P2P file sharing computing
Multi-user network IPTV
games VoIP
Streaming stored video
clips
2 2
Prof. Younghee Lee
Application architectures
Client-server
Peer-to-peer (P2P)
Hybrid of client-server and P2P
3 3
Prof. Younghee Lee
Hybrid of client-server and P2P
Napster
– File transfer P2P
– File search centralized:
» Peers register content at central server
» Peers query same central server to locate content
Instant messaging
– Chatting between two users is P2P
– Presence detection/location centralized:
» User registers its IP address with central server when it comes
online
» User contacts central server to find IP addresses of buddies
4 4
Prof. Younghee Lee
Processes communicating
Process: program running Client process: process
within a host. that initiates
within same host, two
communication
processes communicate Server process: process
using inter-process that waits to be
communication (defined contacted
by OS).
processes in different Note: applications with
hosts communicate by P2P architectures have
exchanging messages client processes & server
processes
5 5
Prof. Younghee Lee
Addressing processes
For a process to receive Identifier includes both
messages, it must have the IP address and port
an identifier numbers associated
A host has a unique32- with the process on the
bit IP address host.
Q: does the IP address
Example port numbers:
of the host on which the
process runs suffice for – HTTP server: 80
identifying the process? – Mail server: 25
Answer: No, many More on this later
processes can be
running on same host
6 6
Prof. Younghee Lee
App-layer protocol defines
Types of messages
exchanged, e.g., request Public-domain protocols:
& response messages defined in RFCs
Syntax of message types: allows for
what fields in messages &
how fields are delineated interoperability
Semantics of the fields, i.e., e.g., HTTP, SMTP
meaning of information in Proprietary protocols:
fields e.g., KaZaA
Rules for when and how
processes send & respond
to messages
7 7
Prof. Younghee Lee
Transport service requirements of common apps
Application Data loss Bandwidth Time Sensitive
file transfer no loss elastic no
e-mail no loss elastic no
Web documents no loss elastic no
real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s msec
video:10kbps-5Mbps
stored audio/video loss-tolerant same as above yes, few secs
interactive games loss-tolerant few kbps up yes, 100’s msec
instant messaging no loss elastic yes and no
TCP? UDP?
8 8
Prof. Younghee Lee
Internet transport protocols services
TCP service:
connection-oriented: setup UDP service:
required between client and unreliable data transfer
server processes between sending and
reliable transport between receiving process
sending and receiving process does not provide:
flow control: sender won’t connection setup, reliability,
overwhelm receiver flow control, congestion
control, timing, or
congestion control: throttle
bandwidth guarantee
sender when network overloaded
does not provide: timing,
minimum bandwidth guarantees Q: why bother? Why is there a
UDP?
9 9
Prof. Younghee Lee
Internet apps: application, transport protocols
Application Underlying
Application layer protocol transport protocol
e-mail SMTP [RFC 2821] TCP
remote terminal access Telnet [RFC 854] TCP
Web HTTP [RFC 2616] TCP
file transfer FTP [RFC 959] TCP
streaming multimedia proprietary TCP or UDP
(e.g. RealNetworks)
Internet telephony proprietary
(e.g., Vonage,Dialpad) typically UDP
10 10
Prof. Younghee Lee
Web and HTTP
First some jargon
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
Example URL:
www.someschool.edu/someDept/pic.gif
host name path name
11 11
Prof. Younghee Lee
HTTP overview
HTTP: hypertext transfer
protocol
Web’s application layer
protocol
PC running
client/server model Explorer
– client: browser that
requests, receives,
“displays” Web objects
– server: Web server sends Server
objects in response to running
requests Apache Web
server
HTTP 1.0: RFC 1945
HTTP 1.1: RFC 2068
Mac running
Navigator
12 12
Prof. Younghee Lee
HTTP overview (continued)
Uses TCP: HTTP is “stateless”
client initiates TCP connection server maintains no
(creates socket) to server, port information about past
client requests
80
server accepts TCP connection
Protocols that maintain “state”
from client
are complex! aside
HTTP messages (application-
past history (state) must be
layer protocol messages)
maintained
exchanged between browser
(HTTP client) and Web server if server/client crashes, their
(HTTP server) views of “state” may be
inconsistent, must be
TCP connection closed
reconciled
Soft State
13 13
Prof. Younghee Lee
HTTP connections
Nonpersistent HTTP Persistent HTTP
At most one object is Multiple objects can be
sent over a TCP sent over single TCP
connection. connection between
HTTP/1.0 uses client and server.
nonpersistent HTTP HTTP/1.1 uses persistent
connections in default
mode
14 14
Prof. Younghee Lee
Nonpersistent HTTP
Suppose user enters URL
www.someSchool.edu/someDepartment/home.index
(contains text,
1a. HTTP client initiates TCP references to 10
connection to HTTP server jpeg images)
(process) at www.someSchool.edu
on port 80 1b. HTTP server at host
www.someSchool.edu waiting
for TCP connection at port 80.
“accepts” connection, notifying
client
2. HTTP client sends HTTP
request message (containing
URL) into TCP connection 3. HTTP server receives request
socket. Message indicates that message, forms response
client wants object message containing requested
someDepartment/home.index object, and sends message into
its socket
time
15 15
Prof. Younghee Lee
Nonpersistent HTTP (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
time 6. Steps 1-5 repeated for each of
10 jpeg objects
16 16
Prof. Younghee Lee
Response time modeling
Definition of RTT: time to send a
small packet to travel from
client to server and back.
Response time: initiate TCP
one RTT to initiate TCP connection
connection RTT
one RTT for HTTP request and request
first few bytes of HTTP file
time to
response to return RTT
transmit
file transmission time file
file
total = 2RTT+transmit time received
time time
17 17
Prof. Younghee Lee
HTTP request message
two types of HTTP messages: request, response
HTTP request message:
– ASCII (human-readable format)
request line
(GET, POST, GET /somedir/page.html HTTP/1.1
HEAD commands) Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr
Carriage return,
line feed (extra carriage return, line feed)
indicates end
of message 18 18
Prof. Younghee Lee
HTTP request message: general format
19 19
Prof. Younghee Lee
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet cis.poly.edu 80 Opens TCP connection to port 80
(default HTTP server port) at cis.poly.edu.
Anything typed in sent
to port 80 at cis.poly.edu
2. Type in a GET HTTP request:
GET /~ross/ HTTP/1.1 By typing this in (hit carriage
Host: cis.poly.edu return twice), you send
this minimal (but complete)
GET request to HTTP server
3. Look at response message sent by HTTP server!
20 20
Prof. Younghee Lee
Let’s look at HTTP in action
telnet example
Ethereal example
21 21
Prof. Younghee Lee
User-server state: cookies
Many major Web sites use Example:
cookies – Susan access Internet
Four components: always from same PC
– She visits a specific e-
1) cookie header line of
commerce site for first time
HTTP response message
– When initial HTTP
2) cookie header line in
requests arrives at site,
HTTP request message
site creates a unique ID
3) cookie file kept on user’s and creates an entry in
host, managed by user’s backend database for ID
browser
4) back-end database at Web
site
22 22
Prof. Younghee Lee
Cookies: keeping “state” (cont.)
client server
Cookie file usual http request msg server
usual http response + creates ID
ebay: 8734 Set-cookie: 1678 1678 for user
Cookie file
usual http request msg
amazon: 1678 cookie: 1678 cookie-
ebay: 8734 specific
usual http response msg action
one week later:
usual http request msg
Cookie file cookie-
cookie: 1678
amazon: 1678 spectific
ebay: 8734 usual http response msg action
23 23
Prof. Younghee Lee
Cookies (continued)
aside
What cookies can bring: Cookies and privacy:
authorization cookies permit sites to
shopping carts
learn a lot about you
you may supply name
recommendations
and e-mail to sites
user session state (Web
search engines use
e-mail)
redirection & cookies to
learn yet more
advertising companies
obtain info across sites
24 24
Prof. Younghee Lee
Web caches (proxy server)
Goal: satisfy client request without involving origin server
user sets browser: Web
accesses via cache origin
server
browser sends all HTTP
requests to cache Proxy
– object in cache: cache server
returns object client
– else cache requests object
from origin server, then
returns object to client
client
origin
server
25 25
Prof. Younghee Lee
More about Web caching
Cache acts as both client and Why Web caching?
server Reduce response time for
Typically cache is installed by client request.
ISP (university, company, Reduce traffic on an
residential ISP) institution’s access link.
Internet dense with caches
enables “poor” content
providers to effectively deliver
content (but so does P2P file
sharing)
26 26
Prof. Younghee Lee
FTP: the file transfer protocol
FTP file transfer
FTP FTP
user client server
interface
user
at host local file remote file
system system
transfer file to/from remote host
client/server model
– client: side that initiates transfer (either to/from remote)
– server: remote host
ftp: RFC 959
ftp server: port 21
27 27
Prof. Younghee Lee
FTP: separate control, data connections
FTP client contacts FTP server TCP control connection
at port 21, specifying TCP as port 21
transport protocol
Client obtains authorization over
control connection TCP data connection
FTP port 20 FTP
Client browses remote directory client server
by sending commands over
control connection.
Server opens a second TCP
When server receives a data connection to transfer
command for a file transfer, the
another file.
server opens a TCP data
connection to client Control connection: “out of
After transferring one file, server band”
closes connection. FTP server maintains “state”:
current directory, earlier
authentication
28 28
Prof. Younghee Lee
FTP commands, responses
Sample commands:
sent as ASCII text over control
Sample return codes
channel status code and phrase (as in
HTTP)
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 (puts) 452 Error writing file
file onto remote host
29 29
Prof. Younghee Lee
Electronic Mail outgoing
message queue
Three major components: user mailbox
user agents user
mail servers agent
simple mail transfer protocol: SMTP mail
user
server
Why user agent and mail agent
server? ; instead of just mail SMTP mail
application over end host server user
User Agent SMTP agent
a.k.a. “mail reader”
composing, editing, reading mail messages SMTP
e.g., Eudora, Outlook, elm, Netscape mail user
Messenger server agent
outgoing, incoming messages stored on
server
user
Directory? agent
DNS: name to ip address, ip address to name user
LDAP: white page, yellow page agent
30 30
Prof. Younghee Lee
Electronic Mail: mail servers
Mail Servers
user
mailbox contains incoming agent
messages for user mail
user
message queue of outgoing (to server
agent
be sent) mail messages
SMTP mail
SMTP protocol between mail
server user
servers to send email
messages SMTP agent
– client: sending mail server SMTP
user
– “server”: receiving mail mail
agent
server server
user
agent
user
agent
31 31
Prof. Younghee Lee
Electronic Mail: SMTP [RFC 2821]
uses TCP to reliably transfer email message from
client to server, port 25
direct transfer: sending server to receiving server
three phases of transfer
– handshaking (greeting)
– transfer of messages
– closure
command/response interaction
– commands: ASCII text
– response: status code and phrase
messages must be in 7-bit ASCII
32 32
Prof. Younghee Lee
Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
message and “to” message over the TCP
bob@someschool.edu connection
2) Alice’s UA sends message to 5) Bob’s mail server places the
her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent to
3) Client side of SMTP opens read message
TCP connection with Bob’s
mail server
1 mail
mail
server user
user server
2 agent
agent 3 6
4 5
33 33
Prof. Younghee Lee
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM:
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO:
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
34 34
Prof. Younghee Lee
Try SMTP interaction for yourself:
telnet servername 25
see 220 reply from server
enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands
above lets you send email without using email client
(reader)
35 35
Prof. Younghee Lee
SMTP: final words
SMTP uses persistent Comparison with HTTP:
connections
HTTP: pull
SMTP requires message
(header & body) to be in 7-bit SMTP: push
ASCII both have ASCII
SMTP server uses command/response interaction,
CRLF.CRLF to determine end status codes
of message
HTTP: each object
encapsulated in its own
response msg
SMTP: multiple objects sent in
multipart msg
36 36
Prof. Younghee Lee
Mail message format
SMTP: protocol for exchanging
email msgs
RFC 822: standard for text header
blank
message format:
line
header lines, e.g.,
– To:
– From: body
– Subject:
different from SMTP commands!
body
– the “message”, ASCII
characters only
37 37
Prof. Younghee Lee
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
38 38
Prof. Younghee Lee
Mail access protocols
SMTP SMTP access user
user
agent protocol agent
sender’s mail receiver’s mail
server server
SMTP: delivery/storage to receiver’s server
Mail access protocol: retrieval from server
– POP: Post Office Protocol [RFC 1939]
» authorization (agent server) and download
– IMAP: Internet Mail Access Protocol [RFC 1730]
» more features (more complex)
» manipulation of stored msgs on server
– HTTP: Hotmail , Yahoo! Mail, etc.
39 39
Prof. Younghee Lee
POP3 protocol S: +OK POP3 server ready
C: user bob
authorization phase S: +OK
C: pass hungry
client commands: S: +OK user successfully logged on
– user: declare username
– pass: password C: list
S: 1 498
server responses S: 2 912
– +OK S: .
– -ERR C: retr 1
S:
transaction phase, client: S: .
list: list message numbers C: dele 1
retr: retrieve message by C: retr 2
number S:
dele: delete S: .
quit C: dele 2
C: quit
S: +OK POP3 server signing off
40 40
Prof. Younghee Lee