Professional Documents
Culture Documents
Layer
our goals:
conceptual,
implementation
aspects of network
application
protocols
transport-layer
service models
client-server
paradigm
peer-to-peer
paradigm
learn about
protocols by
examining popular
application-level
protocols
HTTP
SMTP / POP3 / IMAP
creating network
applications
socket API
Chapter 2: outline
2.1 principles of
network
applications
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
SMTP, POP3,
IMAP
2.5 DNS
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Application architectures
possible structure of applications:
client-server
peer-to-peer (P2P)
Client-server architecture
server:
always-on host
permanent IP address
data centers for scaling
clients:
client/server
P2P architecture
no always-on server
arbitrary end systems
directly communicate
peers request service
from other peers,
provide service in return
to other peers
self scalability new
peers bring new
service capacity, as
well as new service
demands
peers are intermittently
connected and change
IP addresses
complex management
peer-peer
Processes communicating
process: program
running within a
host
clients, servers
client process: process
that initiates
communication
server process:
aside: applications
with P2P architectures
have client processes
& server processes
Application Layer 2-7
Sockets
process
socket
application
process
transport
transport
network
network
link
physical
Internet
link
controlled by
app developer
controlled
by OS
physical
Addressing processes
to receive messages,
process must have
identifier
host device has
unique 32-bit IP
address
Q: does IP address of
host on which process
A: no,
many
runs
suffice
forprocesses
can be running
identifying
the on
same host
process?
more shortly
Application Layer 2-9
types of messages
exchanged,
e.g., request,
response
message syntax:
what fields in
messages & how
fields are delineated
message semantics
meaning of
information in fields
rules for when and how
processes send &
respond to messages
open protocols:
defined in RFCs
allows for
interoperability
e.g., HTTP, SMTP
proprietary protocols:
e.g., Skype
timing
some apps (e.g.,
Internet telephony,
interactive games)
require low delay to
be effective
throughput
some apps (e.g.,
multimedia) require
minimum amount of
throughput to be
effective
other apps (elastic
apps) make use of
whatever throughput
they get
security
encryption, data
integrity,
Application Layer 2-11
data loss
throughput
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
text messaging
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
UDP service:
reliable transport
between sending and
receiving process
flow control: sender
wont overwhelm receiver
congestion control:
throttle sender when
network overloaded
does not provide: timing,
minimum throughput
guarantee, security
connection-oriented:
setup required between
client and server
processes
unreliable data
transfer between
sending and receiving
process
does not provide:
reliability, flow control,
congestion control,
timing, throughput
guarantee, security, or
connection setup,
Chapter 2: outline
2.1 principles of
network
applications
app architectures
app requirements
2.5 DNS
Application Layer 2-14
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:
UDP
TCP
socket
A applicationcreated,
OS-controlled
interface (a door)
into which
application process
can both send and
receive messages
to/from another
application process
Application Layer 2-15
Socket programming
basics
Server must be
running before
client can send
anything to it.
Server must have
a socket (door)
through which it
receives and sends
segments
Similarly client
needs a socket
Socket is locally
identified with a port
number
Analogous to the apt
# in a building
Running example
Client:
User types line of text
Client program sends line to server
Server:
Server receives line of text
Capitalizes all the letters
Sends modified line to client
Client:
Receives line of text
Displays
Client
create socket,
clientSocket =
DatagramSocket()
Create datagram with server IP and
port=x; send datagram via
clientSocket
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();
Application Layer 2-20
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();
}
}
Application Layer 2-21
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);
Application Layer 2-22
Get IP addr
port #, of
sender
Create datagram
to send to client
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram
to socket
serverSocket.send(sendPacket);
}
}
controlled by
application
developer
controlled by
operating
system
process
process
socket
TCP with
buffers,
variables
socket
TCP with
buffers,
variables
host or
server
internet
controlled by
application
developer
controlled by
operating
system
host or
server
Application Layer 2-25
application viewpoint:
TCP provides reliable, in-orde
byte-stream transfer (pipe
between client and server
Application Layer 2-26
Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
Stream jargon
input
stream
Client
Process
process
output
stream
inFromServer
A stream is a
sequence of
characters that flow
into or out of a
process.
An input stream is
attached to some
input source for the
process, e.g.,
keyboard or socket.
An output stream is
attached to an
output source, e.g.,
monitor or socket.
outToServer
monitor
inFromUser
keyboard
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
Application Layer 2-30
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
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
The server socket can have many connections. Each iteration of the while
loop creates a new connection. Whenever a connection is established, a
new thread is created to handle communication between the server and
the new client; and this allows multiple connections to run at the same
time.
Application Layer 2-36
Chapter 2: outline
2.1 principles of
network
applications
app architectures
app requirements
2.5 DNS
Application Layer 2-37
path name
HTTP overview
HTTP: hypertext
transfer protocol
HT
TP
PC running
Firefox browser
req
ues
t
HT
TP
res
p
ons
e
t
es
u
req
server
se
n
running
po
s
e
r
Apache Web
TP
T
server
H
TP
T
H
iphone running
Safari browser
HTTP is stateless
server maintains no
information about
past client requests
aside
protocols that maintain
state are complex!
HTTP connections
non-persistent HTTP persistent HTTP
at most one
multiple objects
object sent over
can be sent over
TCP connection
single TCP
connection
connection then
between client,
closed
server
downloading
multiple objects
required multiple
connections
Application Layer 2-41
Non-persistent HTTP
suppose user enters URL:
www.someSchool.edu/someDepartment/home.index
time
(contains text,
references to 10
jpeg images)
response message
containing html file, displays
html. Parsing html file, finds
10 referenced jpeg objects
time
initiate TCP
connection
RTT
request
file
time to
transmit
file
RTT
file
received
time
time
Persistent HTTP
non-persistent HTTP
issues:
persistent HTTP:
server leaves
connection open after
sending response
subsequent HTTP
messages between
same client/server sent
over open connection
client sends requests as
soon as it encounters a
referenced object
as little as one RTT for
all the referenced
objects
header
lines
carriage return,
line feed at start
of line indicates
end of header lines
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
Keep-Alive: 115\r\n
Connection: keep-alive\r\n
\r\n
Application Layer 2-46
sp
URL
sp
value
version
cr
lf
value
cr
lf
request
line
header
lines
~
~
~
~
~
~
cr
lf
lf
entity body
~
~
body
URL method:
Method
types
HTTP/1.0:
GET
POST
HEAD
asks server to
leave requested
object out of
response
HTTP/1.1:
header
lines
data, e.g.,
requested
HTML file
200 OK
request succeeded, requested object later in this msg
example:
Susan always access
Internet from PC
visits specific ecommerce site for first
time
when initial HTTP
requests arrives at
site, site creates:
unique ID
entry in backend
database for ID
server
usual http request msg
cookie file
ebay 8734
amazon 1678
set-cookie: 1678
cookie: 1678
Amazon server
creates ID
1678 for user create backend
entry database
cookiespecific
action
access
access
usual http request msg
cookie: 1678
cookiespecific
action
Application Layer 2-53
Cookies (continued)
what cookies can
be used for:
authorization
shopping carts
recommendations
user session state
(Web e-mail)
aside
HT
TP
r
proxy
server
equ
est
res
pon
se
t
es
u
req
e
P
ns
T
o
T
p
H
es
r
TP
T
H
H
client TTP
client
st
e
u
req
P
T
se
n
o
HT
p
origin
res
P
T
server
HT
origin
server
cache acts as
both client and
server
server for original
requesting client
client to origin server
typically cache is
installed by ISP
(university,
company,
residential ISP)
Caching example:
assumptions:
consequences:
origin
servers
public
Internet
1.54 Mbps
access link
institutional
network
1 Gbps LAN
assumptions:
1.54 Mbps
154 Mbps
access link
Mbps
consequences:
public
Internet
origin
servers
institutional
network
1 Gbps LAN
msecs
assumptions:
consequences:
origin
servers
public
Internet
1.54 Mbps
access link
institutional
network
1 Gbps LAN
local web
cache
suppose
origin
servers
link utilization:
total
delay
1.54 Mbps
access link
institutional
network
1 Gbps LAN
local web
cache
Conditional GET
server
client
If-modified-since: <date>
HTTP/1.0
304 Not Modified
If-modified-since:
<date>
server: response
contains no object if
cached copy is up-todate:
HTTP/1.0 304 Not
Modified
HTTP response
HTTP response
HTTP/1.0 200 OK
object
not
modified
since
<date>
object
modified
after
<date>
<data>
Application Layer 2-61
Chapter 2: outline
2.1 principles of
network
applications
app architectures
app requirements
2.5 DNS
Application Layer 2-62
Electronic mail
outgoing
message queue
user agents
mail servers
simple mail transfer
protocol: SMTP
User Agent
user
agent
user mailbox
mail
server
user
agent
SMTP
mail
server
user
agent
SMTP
SMTP
mail
server
user
agent
user
agent
user
agent
mailbox contains
incoming messages for
user
message queue of
outgoing (to be sent)
mail messages
SMTP protocol between
mail servers to send
email messages
client: sending mail
server
server: receiving
mail server
user
agent
mail
server
user
agent
SMTP
mail
server
user
agent
SMTP
SMTP
mail
server
user
agent
user
agent
user
agent
1) Alice uses UA to
compose message to
bob@someschool.edu
2) Alices UA sends
message to her mail
server; message placed
in message queue
3) client side of SMTP
opens TCP connection
with Bobs mail server
1 user
agent
2
mail
server
3
Alices mail server
user
agent
mail
server
6
4
5
Bobs mail server
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
Application Layer 2-67
comparison with
HTTP:
HTTP: pull
SMTP: push
header
blank
line
body
commands!
Body: the message
ASCII characters only
SMTP
SMTP
mail access
protocol
user
agent
(e.g., POP,
IMAP)
senders mail
server
receivers mail
server
POP3 protocol
authorization phase
client commands:
user: declare username
pass: password
server responses
+OK
-ERR
transaction phase,
client:
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
on
previous example
uses POP3 download
and delete mode
Bob cannot re-read
e-mail if he
changes client
POP3 download-andkeep: copies of
messages on
different clients
POP3 is stateless
across sessions
IMAP
Chapter 2:
summary
our study of network apps now complete!
application architectures
client-server
P2P
application service
requirements:
reliability, bandwidth, delay
Internet transport service
model
connection-oriented,
reliable: TCP
unreliable, datagrams: UDP
specific protocols:
HTTP
SMTP, POP, IMAP
socket programming:
TCP, UDP sockets
Chapter 2: summary
most importantly: learned about protocols!
typical request/reply
message exchange:
client requests info
or service
server responds with
data, status code
message formats:
headers: fields giving
info about data
data: info being
communicated
important themes: