Chapter2 Tostudent
Chapter2 Tostudent
Application Layer
2: Application Layer 2
Chapter 2: Application Layer
Our goals: learn about protocols
conceptual, by examining popular
implementation application-level
aspects of network protocols
application protocols ❖ HTTP
❖ transport-layer ❖ DNS
service models programming network
❖ client-server applications
paradigm ❖ socket API
2: Application Layer 3
Some network apps
e-mail voice over IP
web real-time video
instant messaging conferencing
remote login grid computing
P2P file sharing
multi-user network
games
streaming stored video
clips
2: Application Layer 4
Creating a network app application
transport
network
data link
2: Application Layer 6
Application architectures
Client-server
2: Application Layer 7
Client-server architecture
server:
❖ always-on host
❖ permanent IP address
❖ server farms for
scaling
clients:
client/server ❖ communicate with server
❖ may be intermittently
connected
❖ may have dynamic IP
addresses
❖ do not communicate
directly with each other
2: Application Layer 8
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 9
Transport service requirements of common apps
2: Application Layer 10
Internet transport protocols services
Application Underlying
Application layer protocol transport protocol
2: Application Layer 12
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
hosts communicate by
exchanging messages
2: Application Layer 13
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
runs suffice for
identifying the process?
2: Application Layer 14
Addressing processes
to receive messages, identifier includes both
process must have IP address and port
identifier numbers associated with
host device has unique process on host.
32-bit IP address Example port numbers:
Q: does IP address of ❖ HTTP server: 80
host on which process ❖ Mail server: 25
runs suffice for to send HTTP message
identifying the to gaia.cs.umass.edu web
process? server:
❖ A: No, many ❖ IP address: 128.119.245.12
processes can be ❖ Port number: 80
running on same host more shortly…
2: Application Layer 15
App-layer protocol defines
Types of messages Public-domain protocols:
exchanged, defined in RFCs
❖ e.g., request, response allows for
Message syntax: interoperability
❖ what fields in messages &
e.g., HTTP, SMTP
how fields are delineated
Proprietary protocols:
Message semantics
❖ meaning of information in
e.g., Skype
fields
Rules for when and how
processes send &
respond to messages
2: Application Layer 16
Chapter 2: Application layer
2.1 Principles of 2.7 Socket programming
network applications with TCP
❖ app architectures
❖ app requirements
2.2 Web and HTTP
2.5 DNS
2: Application Layer 17
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
2: Application Layer 18
HTTP overview
HTTP: hypertext
transfer protocol
Web’s 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 19
HTTP overview (continued)
Uses TCP: HTTP is “stateless”
client initiates TCP server maintains no
connection (creates socket) information about
to server, port 80 past client requests
server accepts TCP
connection from client aside
Protocols that maintain
HTTP messages (application- “state” are complex!
layer protocol messages) past history (state) must
exchanged between browser be maintained
(HTTP client) and Web
if server/client crashes,
server (HTTP server)
their views of “state” may
TCP connection closed
be inconsistent, must be
reconciled
2: Application Layer 20
HTTP connections
Nonpersistent HTTP Persistent HTTP
At most one object is Multiple objects can
sent over a TCP be sent over single
connection. TCP connection
HTTP/1.0 uses between client and
nonpersistent HTTP server.
HTTP/1.1 uses
persistent connections
in default mode
2: Application Layer 21
Nonpersistent HTTP
(contains text,
Suppose user enters URL references to 10
www.someSchool.edu/someDepartment/home.index jpeg images)
time
2: Application Layer 22
Nonpersistent HTTP (cont.)
2: Application Layer 23
HTTP request message
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
2: Application Layer 24
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 25
Trying out HTTP (client side) for yourself
2: Application Layer 26
HTTP request message: general format
2: Application Layer 27
Method types
HTTP/1.0 HTTP/1.1
GET GET, POST, HEAD
POST PUT
HEAD ❖ uploads file in entity
body to path specified
❖ asks server to leave
in URL field
requested object out of
response DELETE
❖ deletes file specified in
the URL field
2: Application Layer 28
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 29
Non-Persistent HTTP: Response time
(performance)
Definition of RTT: time to
send a small packet to
travel from client to
server and back. initiate TCP
connection
Response time: RTT
one RTT to initiate TCP request
file
connection time to
RTT
transmit
one RTT for HTTP file
request and first few file
received
bytes of HTTP response
to return time time
file transmission time
total = 2RTT+transmit time
2: Application Layer 30
Persistent HTTP
2: Application Layer 31
Web caches (proxy server)
Goal: satisfy client request without involving origin server
institutional
cache
2: Application Layer 35
Caching example (cont)
origin
possible solution: install servers
cache public
suppose hit rate is 0.4 Internet
consequence
40% requests will be
satisfied almost immediately
1.5 Mbps
60% requests satisfied by
access link
origin server
utilization of access link institutional
reduced to 60%, resulting in network
10 Mbps LAN
negligible delays (say 10
msec)
total avg delay = Internet
delay + access delay + LAN institutional
delay = .6*(2.01) secs +
.4*milliseconds < 1.4 secs cache
2: Application Layer 36
Conditional GET
2: Application Layer 38
DNS: Domain Name System
2: Application Layer 39
DNS
DNS services Why not centralize DNS?
hostname to IP single point of failure
address translation traffic volume
host aliasing distant centralized
❖ Canonical, alias names database
mail server aliasing maintenance
load distribution
❖ replicated Web doesn’t scale!
servers: set of IP
addresses for one
canonical name
2: Application Layer 40
Distributed, Hierarchical Database
Root DNS Servers
13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
2: Application Layer 42
TLD and Authoritative Servers
Top-level domain (TLD) servers:
❖ responsible for com, org, net, edu, etc, and all
top-level country domains uk, fr, ca, jp.
❖ Network Solutions maintains servers for com TLD
❖ Educause for edu TLD
Authoritative DNS servers:
❖ organization’s DNS servers, providing
authoritative hostname to IP mappings for
organization’s servers (e.g., Web, mail).
❖ can be maintained by organization or service
provider
2: Application Layer 43
Local Name Server
does not strictly belong to hierarchy
each ISP (residential ISP, company,
university) has one.
❖ also called “default name server”
when host makes DNS query, query is sent
to its local DNS server
❖ acts as proxy, forwards query into hierarchy
2: Application Layer 44
DNS name root DNS server
resolution example
2
Host at cis.poly.edu 3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu 5
gaia.cs.umass.edu
2: Application Layer 45
DNS: caching and updating records
once (any) name server learns mapping, it caches
mapping
❖ cache entries timeout (disappear) after some
time
❖ TLD servers typically cached in local name
servers
• Thus root name servers not often visited
update/notify mechanisms under design by IETF
❖ RFC 2136
❖ http://www.ietf.org/html.charters/dnsind-charter.html
2: Application Layer 46
Inserting records into DNS
example: new startup “Network Utopia”
register name networkuptopia.com at DNS registrar
(e.g., Network Solutions)
❖ provide names, IP addresses of authoritative name server
(primary and secondary)
❖ registrar inserts two RRs (resource records) into com TLD
server:
2: Application Layer 47
Chapter 2: Application layer
2.1 Principles of 2.7 Socket programming
network applications with TCP
2.2 Web and HTTP
2.5 DNS
2: Application Layer 48
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
2: Application Layer 49
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
2: Application Layer 50
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 client’s 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 51
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 52
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 53
Socket programming with TCP
Example client-server app:
1) client reads line from
standard input (inFromUser
stream) , sends to server via
socket (outToServer
stream)
2) server reads line from socket
3) server converts line to
uppercase, sends back to
client
4) client reads, prints modified
line from socket
(inFromServer stream)
2: Application Layer 54
Example: Java client (TCP)
import java.io.*;
import java.net.*;
class TCPClient {
clientSocket.close();
}
}
2: Application Layer 56
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
2: Application Layer 57
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 58
Chapter 2: Summary
our study of network apps now complete!
application architectures specific protocols:
❖ client-server ❖ HTTP
❖ DNS
application service
requirements: socket programming
❖ reliability, bandwidth,
delay
Internet transport
service model
❖ connection-oriented,
reliable: TCP
❖ unreliable, datagrams: UDP
2: Application Layer 59
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
2: Application Layer 60