Application Layer: A Note On The Use of These PPT Slides
Application Layer: A Note On The Use of These PPT Slides
Application Layer
2: Application Layer 2
Part 2: Application layer
2: Application Layer 3
Client-server architecture
server:
always-on host
permanent IP address
server farms for scaling
clients:
communicate with
server
may be intermittently
connected
may have dynamic IP
addresses
do not communicate
directly with each other
2: Application Layer 4
Processes communicating
2: Application Layer 5
Addressing processes
to receive messages,
process must have
identifier
host device has
unique32-bit IP
address
Q: does IP address of
host on which process
runs suffice for
identifying the
process?
2: Application Layer 6
Addressing processes
to receive messages, identifier includes both
process must have IP address and port
identifier numbers associated with
host device has process on host.
unique32-bit IP Example port numbers:
address HTTP server: 80
Q: does IP address of Mail server: 25
host on which process to send HTTP message
runs suffice for to gaia.cs.umass.edu web
identifying the server:
process? IP address: 128.119.245.12
Answer: NO, many Port number: 80
processes can be running
more shortly
on same host
2: Application Layer 7
App-layer protocol defines
2: Application Layer 9
Web and HTTP
2: Application Layer 10
HTTP overview
HTTP: hypertext
transfer protocol
Webs application layer PC running
protocol Explorer
client/server model
client: browser that
requests, receives, Server
displays Web objects running
Apache Web
server: Web server
server
sends objects in
response to requests
Mac running
HTTP 1.0: RFC 1945 Navigator
HTTP 1.1: RFC 2068
2: Application Layer 11
HTTP overview (continued)
2: Application Layer 12
HTTP request message
request line
(GET, POST, GET /somedir/page.html HTTP/1.1
DELETE 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
2: Application Layer 13
HTTP request message: general format
2: Application Layer 14
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
header
Last-Modified: Mon, 22 Jun 1998 ...
lines
Content-Length: 6821
Content-Type: text/html
2: Application Layer 15
HTTP response status codes
In first line in server->client response message.
A few sample codes:
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
2: Application Layer 16
Trying out HTTP (client side) for yourself
2: Application Layer 17
Uploading form input
Post method:
Web page often
includes form input URL method:
Input is uploaded to Uses GET method
server in entity body Input is uploaded in
URL field of request
line:
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer 18
Part 2: Application layer
2: Application Layer 19
Sockets
process sends/receives
host or host or
server server
messages to/from its
socket controlled by
app developer
socket analogous to door process process
2: Application Layer 21
Socket programming with TCP
Client must contact server When contacted by client,
server process must first server TCP creates new
be running socket for server process to
server must have created communicate with client
socket (door) that allows server to talk with
welcomes clients contact multiple clients
source port numbers
Client contacts server by:
used to distinguish
creating client-local TCP
clients (more in Chap 3)
socket
specifying IP address, port application viewpoint
number of server process
TCP provides reliable, in-order
When client creates
transfer of bytes (pipe)
socket: client TCP
between client and server
establishes connection to
server TCP
2: Application Layer 22
Client/server socket interaction: TCP
Server (running on hostid) Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
2: Application Layer 23
Stream jargon
keyboard monitor
A stream is a sequence of
characters that flow into
inFromUser
or out of a process. input
stream
inFromServer
outToServer
source, e.g., monitor or
output input
stream stream
socket.
client TCP
clientSocket
socket TCP
socket
2: Application Layer 24
Example: Java client (TCP)
import java.io.*;
import java.net.*;
class TCPClient {
sentence = inFromUser.readLine();
Send line
to server outToServer.writeBytes(sentence + '\n');
clientSocket.close();
}
}
2: Application Layer 26
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
2: Application Layer 27
Example: Java server (TCP), cont
Create output
stream, attached DataOutputStream outToClient =
to socket new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket clientSentence = inFromClient.readLine();
2: Application Layer 28
Part 2: Application layer
2: Application Layer 29
User-server state: cookies
2: Application Layer 30
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
2: Application Layer 31
HTTP connections
2: Application Layer 32
Non-Persistent HTTP: Response time
2: Application Layer 34
Web caches (proxy server)
Goal: satisfy client request without involving origin server
2: Application Layer 35
More about Web caching
2: Application Layer 36
Caching example
origin
Assumptions
servers
average object size = 100,000
bits public
Internet
avg. request rate from
institutions browsers to origin
servers = 15/sec
1.5 Mbps
delay from institutional router
access link
to any origin server and back
institutional
to router = 2 sec
network
10 Mbps LAN
Consequences
utilization on LAN = 15%
utilization on access link = 100%
total delay = Internet delay + institutional
access delay + LAN delay cache
= 2 sec + minutes + milliseconds
2: Application Layer 37
Caching example (cont)
origin
Possible solution
servers
increase bandwidth of access
link to, say, 10 Mbps public
Internet
Consequences
utilization on LAN = 15%
utilization on access link = 15%
10 Mbps
Total delay = Internet delay + access link
access delay + LAN delay
institutional
= 2 sec + msecs + msecs
network
often a costly upgrade 10 Mbps LAN
institutional
cache
2: Application Layer 38
Caching example (cont)
origin
Install cache servers
suppose hit rate is .4 public
Consequence Internet
40% requests will be
satisfied almost immediately
60% requests satisfied by
origin server 1.5 Mbps
access link
utilization of access link
reduced to 60%, resulting in institutional
negligible delays (say 10 network
10 Mbps LAN
msec)
total avg delay = Internet
delay + access delay + LAN
delay = .6*(2.01) secs +
.4*milliseconds < 1.4 secs institutional
cache
2: Application Layer 39
Conditional GET
2: Application Layer 41
FTP: the file transfer protocol
2: Application Layer 42
FTP: separate control, data connections
TCP control connection
FTP client contacts FTP port 21
server at port 21, specifying
TCP as transport protocol
TCP data connection
Client obtains authorization FTP port 20 FTP
over control connection client server
Client browses remote
Server opens another TCP
directory by sending
commands over control data connection to transfer
connection. another file.
Control connection: out of
When server receives file
transfer command, server band
opens 2nd TCP connection (for FTP server maintains state:
file) to client current directory, earlier
After transferring one file, authentication
server closes data Active (PORT) and Passive
connection. (PASV)
FTP commands, responses
2: Application Layer 44
Part 2: Application layer
2: Application Layer 45
Electronic Mail outgoing
message queue
user mailbox
user
Three major components: agent
user agents mail
user
server
mail servers agent
simple mail transfer SMTP mail
protocol: SMTP server user
SMTP agent
User Agent
a.k.a. mail reader SMTP
mail user
composing, editing, reading agent
server
mail messages
e.g., Eudora, Outlook, elm, user
Netscape Messenger SMTP agent
user
outgoing, incoming messages agent
stored on server
2: Application Layer 46
Electronic Mail: mail servers
user
Mail Servers agent
mailbox contains incoming mail
user
messages for user server
agent
message queue of outgoing
SMTP
(to be sent) mail messages mail
server user
SMTP protocol between mail
servers to send email SMTP agent
messages SMTP
client: sending mail mail user
agent
server server
server: receiving mail
user
server agent
user
agent
2: Application Layer 47
Electronic Mail: SMTP [RFC 2821]
1 mail
mail
server user
user server
2 agent
agent 3 6
4 5
2: Application Layer 49
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <[email protected]>
S: 250 [email protected]... Sender ok
C: RCPT TO: <[email protected]>
S: 250 [email protected] ... 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
2: Application Layer 50
Mail access protocols
SMTP SMTP access user
user
agent protocol agent
2: Application Layer 51
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
C: list
pass: password S: 1 498
server responses S: 2 912
S: .
+OK
C: retr 1
-ERR S: <message 1 contents>
transaction phase, client: S: .
C: dele 1
list: list message numbers C: retr 2
retr: retrieve message by S: <message 1 contents>
number S: .
C: dele 2
dele: delete
C: quit
quit S: +OK POP3 server signing off
2: Application Layer 52
POP3 (more) and IMAP
More about POP3 IMAP
Previous example uses Keep all messages in
download and delete one place: the server
mode. Allows user to
Bob cannot re-read e- organize messages in
mail if he changes folders
client IMAP keeps user state
Download-and-keep: across sessions:
copies of messages on names of folders and
different clients mappings between
message IDs and folder
POP3 is stateless
name
across sessions
2: Application Layer 53
Mail message format
2: Application Layer 54
Part 2: Application layer
2: Application Layer 55
Pure P2P architecture
no always-on server
arbitrary end systems
directly communicate
peers are intermittently
connected and change IP
addresses
example: Gnutella
2: Application Layer 56
P2P file sharing
Alice chooses one of
Example the peers, Bob.
Alice runs P2P client File is copied from
application on her Bobs PC to Alices
notebook computer notebook: HTTP
Intermittently While Alice downloads,
connects to Internet; other users uploading
gets new IP address from Alice.
for each connection Alices peer is both a
Asks for Hey Jude Web client and a
transient Web server.
Application displays
other peers that have All peers are servers =
copy of Hey Jude. highly scalable!
2: Application Layer 57
P2P: centralized directory
Bob
original Napster design centralized
1) when peer connects, it directory server
1
informs central server: peers
IP address 1
content
1 3
2) Alice queries for Hey
2
Jude 1
Alice
2: Application Layer 58
P2P: problems with centralized directory
2: Application Layer 59
Query flooding: Gnutella
2: Application Layer 60
Gnutella: protocol
File transfer:
Query message HTTP
sent over existing TCP
connections
Query
peers forward
QueryHit
Query message
QueryHit
sent over
reverse
path
Scalability:
limited scope
flooding
2: Application Layer 61
Gnutella: Peer joining
2: Application Layer 62
Exploiting heterogeneity: KaZaA
neighoring relationships
in overlay network
2: Application Layer 63
KaZaA: Querying
2: Application Layer 64
Hybrid of client-server and P2P
Skype/SIP
Internet telephony app
Finding address of remote party: centralized server(s)
Client-client connection is direct (not through server)
2: Application Layer 65
Part 2: Application layer
2: Application Layer 66
What transport service does an app need?
Data loss Bandwidth
some apps (e.g., audio) can some apps (e.g.,
tolerate some loss multimedia) require
other apps (e.g., file minimum amount of
transfer, telnet) require bandwidth to be
100% reliable data
effective
transfer
other apps (elastic
Timing apps) make use of
some apps (e.g., whatever bandwidth
Internet telephony, they get
interactive games)
require low delay to be
effective
2: Application Layer 67
Transport service requirements of common apps
2: Application Layer 68
Internet transport protocols services
2: Application Layer 69
Socket programming with UDP
2: Application Layer 70
Client/server socket interaction: UDP
Server (running on hostid) Client
write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port number close
clientSocket
2: Application Layer 71
Example: Java client (UDP)
keyboard monitor
inFromUser
input
stream
Client
Process
Input: receives
process
packet (recall
Output: sends thatTCP received
packet (recall byte stream)
receivePacket
sendPacket
that TCP sent UDP
packet
UDP
packet
byte stream)
client UDP
clientSocket
socket UDP
socket
2: Application Layer 72
Example: Java client (UDP)
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception
{
Create
input stream BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Create
client socket DatagramSocket clientSocket = new DatagramSocket();
Translate
InetAddress IPAddress = InetAddress.getByName("hostname");
hostname to IP
address using DNS byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
2: Application Layer 74
Example: Java server (UDP)
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception
Create {
datagram socket
DatagramSocket serverSocket = new DatagramSocket(9876);
at port 9876
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
Create space for
DatagramPacket receivePacket =
received datagram
new DatagramPacket(receiveData, receiveData.length);
Receive serverSocket.receive(receivePacket);
datagram
2: Application Layer 75
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
Get IP addr
InetAddress IPAddress = receivePacket.getAddress();
port #, of
sender int port = receivePacket.getPort();
sendData = capitalizedSentence.getBytes();
Create datagram
DatagramPacket sendPacket =
to send to client new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram serverSocket.send(sendPacket);
to socket }
}
} End of while loop,
loop back and wait for
another datagram
2: Application Layer 76