Professional Documents
Culture Documents
Application Layer
2: Application Layer
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
service
2: Application Layer
2: Application Layer
by examining popular
application-level
protocols
HTTP
FTP
SMTP / POP3 / IMAP
DNS
programming network
applications
socket API
2: Application Layer
Internet telephone
File transfer
Real-time video
E-mail
Instant messaging
Remote login
P2P file sharing
Multi-user network
conference
Massive parallel
computing
DNS directory
service
games
Streaming stored
video clips
2: Application Layer
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
2: Application Layer
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
service
2: Application Layer
Application architectures
Broad architectural plan of the application
Application Architecture vs Network Architecture
Network architecture is fixed and provide services to
applications
Application architecture is designed by the application
developer and dictates how the application is organized
over the various end systems
Three architectures
Client-server
Peer-to-peer (P2P)
Hybrid of client-server and P2P
2: Application Layer
Client-server architecture
server:
always-on host
Provide services
permanent IP address
server farms for scaling
clients:
Example:
Sometimes on or always on
communicate with server
may be intermittently connected
may have dynamic IP addresses
do not communicate directly
with each other
2: Application Layer
directly communicate
peers are intermittently
connected and change IP
addresses
example: Gnutella
10
2: Application Layer
11
One peer may have the only copy of an important file and that
peer can drop out of the community at any time
2: Application Layer
12
Instant messaging
13
Processes communicating
Process: program running within a host.
within same host, two processes communicate using
inter-process communication (defined by OS).
processes in different hosts communicate by
exchanging messages
A sending process creates and sends messages into
the network; a receiving process receives these
messages and possibly responds by sending messages
back.
Processes communicate with each other by using the
application layer of the five layer protocol stack
2: Application Layer
14
2: Application Layer
15
Sockets
process sends/receives
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
TCP with
buffers,
variables
controlled
by OS
Socket is the interface between the application layer and the transport
16
Sockets (2)
API between the application
Control of everything on
application layer side of socket
Little control of the transport
layer side of the socket
layer side
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
TCP with
buffers,
variables
controlled
by OS
2: Application Layer
17
Addressing processes
For a process to receive
Identifier includes
HTTP server: 80
Mail server: 25
2: Application Layer
18
App-layer protocols
Public-domain protocols:
defined in RFCs
allows for
interoperability
eg, HTTP, SMTP
Proprietary protocols:
eg, KaZaA
2: Application Layer
19
network application.
Example web client/server application
20
Timing
realtime applications)
require low delay to be
effective
Eg. Internet telephony,
teleconferencing,
interactive games
Bandwidth
some apps (e.g., multimedia)
2: Application Layer
21
Bandwidth
Time Sensitive
file transfer
e-mail
Web documents
real-time audio/video
no loss
no loss
no loss
loss-tolerant
no
no
no
yes, 100s msec
stored audio/video
interactive games
instant messaging
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
Application
2: Application Layer
22
connection-oriented:
Data transfer
connection termination
23
2: Application Layer
24
Application
layer protocol
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
2: Application Layer
25
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2.5 DNS-directory
service
2: Application Layer
26
27
path name
28
2: Application Layer
29
2: Application Layer
30
HTTP overview
HTTP: hypertext transfer
protocol
Webs application layer protocol
client/server model
HT
TP
r
equ
est
PC running HT
TP
res
Explorer
pon
se
st
e
u
eq
r
se Server
P
n
T
o
p
running
HT
es
r
TP
Apache Web
T
H
server
Mac running
Navigator
2: Application Layer
31
HTTP is stateless
server maintains no
aside
32
HTTP connections
Nonpersistent HTTP
At most one object is
sent over a TCP
connection.
HTTP/1.0 uses
nonpersistent HTTP
Persistent HTTP
Multiple objects can
be sent over single
TCP connection
between client and
server.
HTTP/1.1 uses
persistent connections
in default mode
2: Application Layer
33
Nonpersistent HTTP
Steps of transferring a web page from server to client
Suppose user enters URL
(contains text,
references to 10
www.someSchool.edu/someDepartment/home.index
jpeg images)
time
www.someSchool.edu waiting
for TCP connection at port 80.
accepts connection,
notifying client
34
time
connection.
10 jpeg objects
35
Estimate the amount of time that elapses from when a client requests
the base HTML file until the entire file is received by the client
Response time:
one RTT to initiate TCP
connection
one RTT for HTTP request
and first few bytes of HTTP
response to return
file transmission time
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
2: Application Layer
36
Persistent HTTP
Nonpersistent HTTP issues:
Persistent HTTP
default in HTTP/1.1
client sends requests as soon as it
encounters a referenced object
Back-to-back requests new
request before receiving a
response to a previous request
as little as one RTT for all the
referenced objects
2: Application Layer
37
request, response
Carriage return,
line feed
indicates end
of message
2: Application Layer
38
2: Application Layer
39
URL method:
Uses GET method
Input is uploaded in
URL field of request
line:
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer
40
Method types
HTTP/1.0
GET
POST
HEAD
HTTP/1.1
GET, POST, HEAD
PUT
DELETE
41
Entity body
(data), e.g.,
requested
HTML file
HTTP/1.1 200 OK
Connection: close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 ...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
2: Application Layer
42
2: Application Layer
43
200 OK
44
45
Header
Exchanges additional information between the client and the server
For example, the client can request that the document be sent in a special format or
the server can send extra information about the document.
The header can be one or more header lines
Header name
Header value
2: Application Layer
46
Header (2)
Request line
Status line
General headers
General headers
Request headers
Response headers
Entity headers
Entity headers
A blank line
A blank line
Body
Body
Request message
Response message
2: Application Layer
47
General Header
The general header gives general information about
Header
Description
Cache-control
Connection
Date
MIME-version
Upgrade
2: Application Layer
48
Request Header
Can be present only in a request message
It specifies the clients configuration and the clients
Header
Description
Accept
Accept-charset
Accept-encoding
Accept-language
Authorization
From
Host
If-modified-since
If-match
If-non-match
49
Description
If-range
If-unmodified-since
Referrer
User-agent
2: Application Layer
50
Response Header
Can be present only in a response message
It specifies the servers configuration and special information
Header
Description
Accept-range
Age
Public
Retry-after
Server
2: Application Layer
51
Entity Header
Gives information about the body of the document
Although it is present in response messages, some request messages, such
as POST or PUT methods, that contain a body also use this type of header
Header
Description
Allow
Content-encoding
Content-language
Content-length
Content-range
Content-type
Etag
expires
Last-modified
location
52
2: Application Layer
53
Methods
PATCH method
PATCH is similar to PUT except that the request contain
only a list of differences that should be implemented in
the existing file.
COPY method
The COPY method is used to copy a file to another location
The location of the source file is given in the request line
(URL)
The location of the destination is given in the entity
header.
2: Application Layer
54
Methods (2)
MOVE method
The MOVE method is used to move a file to another
location.
The location of the source file is given in the request line
(URL)
The location of the destination is given in the entity header
LINK method
The LINK method is used to create a link or links from a
document to another location
The location of the file is given in the request line (URL)
The location of the destination is given in the entity header
2: Application Layer
55
Methods (3)
UNLINK method
The UNLINK method is used to delete links created by the
LINK method
OPTION method
The OPTION method is used by the client to ask the
server about available options.
2: Application Layer
56
Status Codes
Code
Phrase
Description
Informational
100
Continue
101
Switching
Success
200
OK
201
Created
202
Accepted
204
No Content
2: Application Layer
57
Phrase
Description
Redirection
301
Bad request
401
Unauthorized
403
Forbidden
Service is denied
404
Not found
405
Method not
allowed
Not acceptable
406
58
Phrase
Description
Server error
500
501
503
Internal server
error
Not
implemented
Service
unavailable
2: Application Layer
59
2: Application Layer
60
Example:
61
ebay: 8734
Cookie file
amazon: 1678
ebay: 8734
Set-cookie: 1678
usual http request msg
cookie: 1678
usual http response msg
cookie: 1678
usual http response msg
n
server
da try i
t ab n b
creates ID
as ac
e
ke
nd
1678 for user
cookiespecific
action
ss
acce
ac
ce
ss
Cookie file
server
cookiespectific
action
2: Application Layer
62
Cookies (continued)
What cookies can bring:
authorization
shopping carts
recommendations
user session state
(Web e-mail)
aside
63
HTTP Content
HTTP is used to transfer web pages (HTML files), GIFs,
2: Application Layer
64
origin
server
Proxy
HT
TP
est
u
q
req server
re
H
u
P
e
T
se
T
st
client TP
n
T
o
H
p
res
res
pon
P
se
TT
H
st
e
u
req
P
nse
T
o
p
HT
es
r
TP
T
H
client
origin
server
2: Application Layer
65
and server
Typically cache is installed
by ISP (university,
company, residential ISP)
client request.
Reduce traffic on an
institutions access link.
Internet dense with caches
enables poor content
providers to effectively
deliver content (but so
does P2P file sharing)
2: Application Layer
66
Caching example
Assumptions
average object size = 100,000
bits
avg. request rate from
institutions browsers to
origin servers = 15/sec
delay from institutional router
to any origin server and back
to router = 2 sec
Consequences
origin
servers
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
2: Application Layer
67
origin
servers
public
Internet
= Internet delay +
access delay + LAN delay
= 2 sec + msecs + msecs
often a costly upgrade
10 Mbps
access link
Total delay
institutional
network
10 Mbps LAN
2: Application Layer
68
Consequence
origin
servers
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer
69
Conditional GET
Caching reduces response
time
Problem
GET method
If-modified-since: <date>
header line
2: Application Layer
70
GET /fruit/kiwi.gif
HTTP/1.1
Host:
www.exotiquecuisine.com
HTTP/1.1 200 OK
Date: Mon, 7 jul 2003, 15:39:29
Server: Apache/1.3.0 (Unix)
Last-Modified: Wed, 2 jul 2003 09:23:24
Content-Type: image/gif
(data
data
data
data ...)
Example (contd)
o The cache forwards the
2: Application Layer
71
server
cache
HTTP request msg
If-modified-since:
<date>
HTTP response
object
not
modified
HTTP/1.1
304 Not Modified
HTTP response
object
modified
HTTP/1.1 200 OK
<data>
2: Application Layer
72
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
73
2: Application Layer
74
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
2: Application Layer
75
FTP
client
FTP
server
76
control channel
USER username
PASS password
current directory
(gets) file
in HTTP)
331 Username OK,
password required
125 data connection
already open;
transfer starting
425 Cant open data
connection
452 Error writing
file
959
2: Application Layer
77
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
78
Electronic Mail
outgoing
message queue
user mailbox
user
agent
mail
server
SMTP
SMTP
User Agent
a.k.a. mail reader
composing, editing, reading mail
messages
e.g., Eudora, Outlook, elm,
Netscape Messenger all GUI
based
outgoing, incoming messages
stored on server
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
79
Mail Servers
mailbox contains incoming
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
80
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
2: Application Layer
81
1
user
agent
mail
server
3
mail
server
4
user
agent
2: Application Layer
82
220 hamburger.edu
HELO crepes.fr
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <alice@crepes.fr>
250 alice@crepes.fr... Sender ok
RCPT TO: <bob@hamburger.edu>
250 bob@hamburger.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 hamburger.edu closing connection
2: Application Layer
83
commands
above lets you send email without using email client
(reader)
2: Application Layer
84
connections
SMTP requires message
(header & body) to be in 7bit ASCII
SMTP server uses
CRLF.CRLF to determine
end of message
SMTP: ASCII
command/response interaction,
status codes
restriction
85
header
blank
line
body
body
86
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
2: Application Layer
87
Received Message
Header lines inserted by the SMTP receiving server
The receiving appends a Received: header line
2: Application Layer
88
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
89
POP3 protocol
authorization phase
client commands:
user: declare username
pass: password
server responses
+OK
-ERR
transaction phase
Retrieves messages, mark messages for
deletion, remove deletion marks, obtain
mail statistics
list: list message numbers
retr: retrieve message by number
dele: delete
Quit
update phase
Delete the messages that were marked for
deletion
S:
C:
S:
C:
S:
C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:
list
1 498
2 912
.
retr 1
<message 1 contents>
.
dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off
2: Application Layer
90
on
2: Application Layer
91
to obtain components of
messages.
2: Application Layer
92
Web-Based E-mail
Accessing email
93
messages in a hierarchy of
folders on the remote
server.
Many implementations of
web-based e-mail use an
IMAP server to provide the
folder functionality
94
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
95
Q: map between IP
addresses and name ?
2: Application Layer
96
DNS Example
DNS is commonly employed by other application layer protocols.
3.
4.
5.
97
DNS
DNS services
Hostname to IP address
translation
Host aliasing
Load distribution
Replicated Web servers: set of
IP addresses for one canonical
name
98
2: Application Layer
99
m WIDE Tokyo
e NASA Mt View, CA
f Internet Software C. Palo Alto, CA (and 17
other locations)
13 root name
servers worldwide
2: Application Layer
100
2: Application Layer
101
2: Application Layer
102
Example
Host at cis.poly.edu
3
4
5
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer
103
Recursive queries
recursive query:
resolution on
contacted name
server
heavy load?
iterated query:
contacted server
3
7
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer
104
5
local DNS server
dns.poly.edu
gaia.cs.umass.edu
2: Application Layer
105
DNS records
DNS: distributed db storing resource records (RR)
RR format:
Type=A
name is hostname
value is IP address
(relay1.bar.foo.com, 145.37.93.126, A)
Provide standard hostname to IP
address mapping
Type=NS
106
15 16
31
msg header
identification: 16 bit # for
2: Application Layer
107
15 16
Eg.: the answer field in a reply to an MX query contains a resource record providing the canonical
hostname of a mail server. The additional section contains a Type A record providing the IP
address for the canonical hostname of the mail server.
2: Application Layer
108
nslookup program
How would you send a DNS query message to DNS
server?
After invoking nslookup program, you can send a DNS
query to any DNS server (root, TLD or authoritative)
After receiving the reply message from the DNS
server, nslookup will display the records included in
the reply.
As an alternative to running nslookup from your own
host, you can visit one of many web sites that allow
you to remotely employ nslookup.
2: Application Layer
109
110
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
111
Introduction
More traffic on Internet than web application
MP3, videos, software, documents, images
Protocol and networking issues in P2P file sharing
2: Application Layer
112
113
2: Application Layer
114
ma
r
o
f
In
1
centralized
directory server
Q
ue
ry
fo
rc
te
on
nt
peers
ansfe
r
IP address
content
date
p
u
nd
File t
r
Bob
Alice
2: Application Layer
115
bottleneck
Copyright
infringement
file transfer is
decentralized, but
locating content is
highly centralized
2: Application Layer
116
implementing protocol
117
Gnutella: protocol
Query message
Qu
File transfer:
HTTP
Query
QueryHit
Qu
ery
er
y
2: Application Layer
118
1.
2.
3.
4.
5.
119
traffic
Each peer is either a
group leader or assigned
to a group leader.
o rd in a ry p e e r
g r o u p - le a d e r p e e r
n e ig h o r in g r e la tio n s h ip s
in o v e r la y n e tw o r k
2: Application Layer
120
KaZaA: Querying
Each file has a hash and a descriptor
Client sends keyword query to its group
leader
Group leader responds with matches:
121
KaZaA tricks
Techniques to improve its performance
Limit on simultaneous uploads
Request queuing
Incentive priorities
Parallel downloading
uses byte-range header of HTTP to request different
portions of the file from different peers
2: Application Layer
122
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
123
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
Socket API
introduced in BSD4.1 UNIX,
1981
explicitly created, used,
released by apps
client/server paradigm
two types of transport service
via socket API:
unreliable datagram
reliable, byte streamoriented
socket
a host-local,
application-created,
OS-controlled interface
(a door) into which
application process can
both send and
receive messages to/from
another application
process
2: Application Layer
124
controlled by
application
developer
controlled by
operating
system
process
process
socket
TCP with
buffers,
variables
host or
server
internet
socket
TCP with
buffers,
variables
controlled by
application
developer
controlled by
operating
system
host or
server
2: Application Layer
125
application viewpoint
126
2: Application Layer
127
Stream jargon
keyboard
monitor
input
stream
Client
Process
output
stream
inFromServer
process
outToServer
inFromUser
A stream is a sequence of
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
2: Application Layer
128
input
stream
Client
Process
process
output
stream
inFromServer
outToServer
monitor
inFromUser
keyboard
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
2: Application Layer
129
Client
(running on hostid)
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
130
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
2: Application Layer
131
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
Send line
to server
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
Read line
from server
132
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
2: Application Layer
133
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
2: Application Layer
134
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
135
application viewpoint
2: Application Layer
136
receivePacket
sendPacket
inFromUser
Input: receives
packet (TCP
received byte
stream)
2: Application Layer
137
(running on hostid)
create socket,
port=x, for
incoming request:
serverSocket =
DatagramSocket()
Client
create socket,
clientSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket
2: Application Layer
138
Create
input stream
Create
client socket
Translate
hostname to IP
address using DNS
class UDPClient {
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("hostname");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
2: Application Layer
139
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
Read datagram
from server
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
2: Application Layer
140
Create
datagram socket
at port 9876
class UDPServer {
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
2: Application Layer
141
Get IP addr
port #, of
sender
Create datagram
to send to client
Write out
datagram
to socket
}
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
serverSocket.send(sendPacket);
}
}
2: Application Layer
142
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
143
request
accepts the request
parses header
obtains requested file
from servers file
system
creates HTTP response
message:
144
Chapter 2: Summary
Our study of network apps now complete!
Application architectures
client-server
P2P
hybrid
application service
requirements:
specific protocols:
HTTP
FTP
SMTP, POP, IMAP
DNS
socket programming
model
2: Application Layer
145
Chapter 2: Summary
Most importantly: learned about protocols
typical request/reply
message exchange:
message formats:
headers: fields giving info
about data
data: info being
communicated
in-band, out-of-band
centralized vs. decentralized
stateless vs. stateful
reliable vs. unreliable msg
transfer
complexity at network
edge
2: Application Layer
146
End
2: Application Layer
147