Beruflich Dokumente
Kultur Dokumente
Application Layer
Goals: More goals
❒ conceptual + ❒ specific protocols:
implementation aspects of ❍ http
network application
protocols
❍ ftp
❍ client server paradigm
❍ SMTP
❍ service models
❍ pop
❒ learn about protocols by
❍ DNS
examining popular ❒ programming network
application-level protocols applications
❍ socket programming
1
Applications and application-layer protocols
“user space”
❍ exchange messages to
implement app
❍ e.g., email, file transfer, the
Web
Application-layer protocols
application
application
❍ one “piece” of an app transport
transport
network
network data link
❍ define messages exchanged data link physical
physical
by apps and actions taken
❍ user services provided by
lower layer protocols
2
Client-server paradigm
Typical network app has two application
pieces: client and server transport
network
data link
physical
Client:
❒ initiates contact with server request
(“speaks first”)
❒ typically requests service from
server,
❒ e.g.: request WWW page, send reply
email
application
Server: transport
network
data link
❒ provides requested service to physical
client
❒ e.g., sends requested WWW
page, receives/stores received
email
3
Application-layer protocols (cont).
5
Transport service requirements of common apps
6
Services provided by Internet transport
protocols
TCP service: UDP service:
❒ connection-oriented: setup ❒ unreliable data transfer
required between client, server 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 providing: timing, Q: why bother? Why is there a
minimum bandwidth UDP?
guarantees
7
Internet apps: their protocols and transport
protocols
Application Underlying
Application layer protocol transport protocol
8
WWW: the http protocol
9
The http protocol: more
http: TCP transport service: http is “stateless”
❒ client initiates TCP connection ❒ server maintains no
(creates socket) to server, information about past
port 80 client requests
❒ server accepts TCP
connection from client aside
Protocols that maintain “state”
❒ http messages (application- are complex!
layer protocol messages) ❒ past history (state) must be
exchanged between browser maintained
(http client) and WWW server
❒ if server/client crashes, their
(http server)
views of “state” may be
❒ TCP connection closed
inconsistent, must be
reconciled
10
http example
Suppose user enters URL (contains text,
www.someSchool.edu/someDepartment/home.index references to 10
jpeg images)
1a. http client initiates TCP
connection to http server
(process) at
1b. http server at host
www.someSchool.edu waiting
www.someSchool.edu. Port 80
for TCP connection at port 80.
is default for http server.
“accepts” connection, notifying
client
2. http client sends http request
message (containing URL) into
TCP connection socket 3. http server receives request
message, forms response
message containing requested
object
(someDepartment/home.index),
sends message into socket
time
11
http example (cont.)
4. http server closes TCP
connection.
5. http client receives response
message containing html file,
displays html. Parsing html file,
findis10 referenced jpeg objects
12
http message format: request
request line
(GET, POST, GET /somedir/page.html HTTP/1.1
HEAD commands) Connection: close
User-agent: Mozilla/4.0
header Accept: text/html, image/gif,image/jpeg
lines Accept-language:fr
Carriage return,
(extra carriage return, line feed)
line feed
indicates end
of message
13
http request message: general format
14
http message format: reply
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection: close
Date: Thu, 06 Aug 1998 12:00:15 GMT
header Server: Apache/1.3.0 (Unix)
lines Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
data, e.g.,
requested
html file
15
http reply 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
16
Trying out http (client side) for yourself
17
User-server interaction: authentication
18
User-server interaction: cookies
19
User-server interaction: conditional GET
21
Why WWW Caching?
origin
servers
Assume: cache is “close”
to client (e.g., in same public
Internet
network)
❒ smaller response time:
cache “closer” to client 1.5 Mbps
❒ decrease traffic to access link
institutional
distant servers network
10 Mbps LAN
❍ link out of
institutional/local ISP
network often bottleneck
institutional
cache
22
ftp: the file transfer protocol
23
ftp: separate control, data connections
25
Electronic Mail outgoing
message queue
user mailbox
user
Three major components: agent
❒ user agents mail
user
server
❒ mail servers agent
❒ simple mail transfer protocol: SMTP mail
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, pine, elm, user
Netscape Messenger agent
user
❒ outgoing, incoming messages agent
stored on server
26
Electronic Mail: mail servers
user
Mail Servers agent
❒ mailbox contains incoming mail
user
messages (yet ot be read) for server
agent
user
❒ message queue of outgoing
SMTP mail
server user
(to be sent) mail messages
❒ smtp protocol between mail SMTP agent
27
Electronic Mail: smtp [RFC 821]
❒ uses tcp to reliably transfer email msg from client to server,
port 25
❒ direct transfer: sending server to receiving server
❒ three phases of transfer
❍ handshaking (greeting)
❍ transfer
❍ closure
❒ command/response interaction
❍ commands: ASCI text
❍ response: status code and phrase
28
Sample smtp interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
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
29
smtp: final words
try smtp interaction for Comparison with http
yourself: ❒ http: pull
❒ telnet servername 25 ❒ email: push
❒ see 220 reply from server
❒ both have ASCII
❒ enter HELO, MAIL FROM,
RCPT TO, DATA, QUIT command/response
interaction, status codes
commands
above lets you send email ❒ http: multiple objects in file
without using email client sent in separate connections
(reader) ❒ smtp: multiple message
parts sent in one connection
30
Mail message format
31
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 .
32
MIME types
Text Video
❒ example subtypes: plain, ❒ example subtypes:
html mpeg, quicktime
Image
❒ example subtypes: jpeg,
Application
gif ❒ other data that must be
processed by reader
before “viewable”
Audio
❒ example subtypes:
❒ exampe subtypes: basic (8-
msword, octet-
bit mu-law encoded),
32kadpcm (32 kbps
stream
coding)
33
Mail access protocols
SMTP SMTP POP3 or user
user
agent IMAP agent
34
POP3 protocol S: +OK POP3 server ready
C: user alice
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
❍ +OK
S: .
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
35
DNS: Domain Name System
36
DNS name servers
Why not centralize DNS? ❒ no server has all name-to-
❒ single point of failure IP address mappings
❒ traffic volume local name servers:
❍ each ISP, company has
❒ distant centralized
local (default) name server
database ❍ host DNS query first goes to
❒ maintenance local name server
authoritative name server:
doesn’t scale! ❍ for a host: stores that host’s
IP address, name
❍ can perform name/address
translation for that host’s
name
37
DNS: Root name servers
❒ contacted by local name
server that can not
resolve name
❒ root name server:
❍ contacts
authoritative name
server if name
mapping not known
❍ gets mapping
❍ returns mapping to
local name server
❒ ~ dozen root name
servers worldwide
38
Simple DNS example root name server
39
DNS example root name server
gaia.cs.umass.edu
40
DNS: iterated queries root name server
gaia.cs.umass.edu
41
DNS: caching and updating records
❒ once (any) name server learns mapping, it caches
mapping
❍ cache entries timeout (disappear) after some
time
❒ update/notify mechanisms under design by IETF
❍ RFC 2136
❍ http://www.ietf.org/html.charters/dnsind-charter.html
42
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type,ttl)
❒ Type=A ❒ Type=CNAME
❍ name is hostname ❍ name is an alias name for
❍ value is IP address some “cannonical” (the
real) name
❒ Type=NS ❍ value is cannonical
❍ name is domain (e.g. name
foo.com)
❒ Type=MX
❍ value is IP address of
❍ value is hostname of
authoritative name server
for this domain mailserver associated with
name
43
DNS protocol, messages
DNS protocol : query and repy messages, both with
same message format
msg header
❒ identification: 16 bit # for
query, repy to query uses
same #
❒ flags:
❍ query or reply
❍ recursion desired
❍ recursion available
❍ reply is authoritative
44
DNS protocol, messages
RRs in reponse
to query
records for
authoritative servers
additional “helpful”
info that may be used
45
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
46
Socket-programming using TCP
Socket: a door between application process and end-
end-transport protocol (UCP or TCP)
TCP service: reliable transfer of bytes from one process
to another
controlled by
controlled by process application
application process
developer
developer socket socket
TCP with TCP with controlled by
controlled by
buffers, operating
operating buffers, internet system
system variables variables
host or host or
server server
47
Socket programming with TCP
Client must contact server ❒ When client creates socket:
❒ server process must first be client TCP establishes
running connection to server TCP
❒ server must have created ❒ When contacted by client,
socket (door) that welcomes server TCP creates new
client’s contact socket for server process to
communicate with client
Client contacts server by:
❍ allows server to talk with
❒ creating client-local TCP
multiple clients
socket
❒ specifying IP address, port application viewpoint
number of server process
TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server
48
Socket programming with TCP
iinFromServer
❒ server reads line from socket
outToServer
❒ server converts line to
uppercase, sends back to client
❒ client reads, prints modified
line from socket inFromUser
(inFromServer stream)
client socket
49
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
connectionSocket
close
connectionSocket close
clientSocket
50
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();
}
}
52
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
53
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();
54
Socket programming with UDP
55
Client/server socket interaction: UDP
Server (running on hostid) Client
create socket,
port=x, for create socket,
clientSocket =
incoming request: DatagramSocket()
serverSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket
read request from
serverSocket
write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port umber close
clientSocket
56
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];
58
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
59
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 client connection
60
Chapter 2: Summary
Our study of network apps now complete!
❒ application service ❒ specific protocols:
requirements: ❍ http
❍ reliability, bandwidth, ❍ ftp
delay ❍ smtp, pop3
❒ client-server paradigm ❍ dns
❒ Internet transport ❒ socket programming
service model ❍ client/server
❍ connection-oriented, implementation
reliable: TCP ❍ using tcp, udp sockets
❍ unreliable, datagrams:
UDP
61
Chapter 2: Summary
Most importantly: learned about protocols
❒ typical request/reply
❒ control vs. data msgs
message exchange:
❍ in-based, out-of-band
❍ client requests info or
service
❒ centralized vs. decentralized
❍ server responds with
❒ stateless vs. stateful
data, status code ❒ reliable vs. unreliable msg
transfer
❒ message formats:
❒ “complexity at network edge”
❍ headers: fields giving info
❒ security: authentication
about data
❍ data: info being
communicated
62