9/16/2003-9/18/2003 the application layer and java programming september 16-18, 2003

40
9/16/2003-9/18/200 3 The Application Layer and Java Programming September 16-18, 2003

Post on 21-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

9/16/2003-9/18/2003

The Application Layer and Java Programming

September 16-18, 2003

9/16/2003-9/18/2003

Assignments

• Homework 2– Chapter 2 review

• Finish 2.1-2.2 and 2.6-1.8

• Read 2.3-2.5 and 2.9

9/16/2003-9/18/2003

Application Layer

• Goals– Understand application-layer concepts and

protocols• Real examples – HTTP, FTP, SMTP

– Understand application development• Socket programming

– CDNs (if time)

9/16/2003-9/18/2003

Application CommunicationWeb

Browser

WebServer

9/16/2003-9/18/2003

Jargon

• Process – running program

• Application-layer protocol – defines communication between processes– HTTP

• User agent – entity that interfaces with the user and network– Web browser

9/16/2003-9/18/2003

Applications and App-Layer Protocols

Web Browser

Web ServerHTTP

UI

HTTP …File

Access

9/16/2003-9/18/2003

Protocol Stack

Web Browser

HTTP

UI

Application

Transport

Network

Link

Physical

9/16/2003-9/18/2003

Protocols• Define

– Types of messages exchanged• request/response

– Syntax of message types• what fields in messages & how fields are delineated

– Semantics of the fields• meaning of information in fields

– Rules for when and how processes send & respond to messages• Public-domain protocols

– defined in RFCs– allow for interoperability– HTTP, SMTP

• Proprietary protocols– KaZaA

9/16/2003-9/18/2003

Client-Server Paradigmapplicatio

ntransportnetworkdata linkphysical

application

transportnetworkdata linkphysical

Client• initiates contact with server • typically requests service from

server• Web: client implemented in

browser

Server• provides requested service to

client• Web: server sends requested

Web page

request

reply

9/16/2003-9/18/2003

Sockets• Interface between app

and transport layers• Send/receive messages

to/from socket• API

– choice of transport protocol

– ability to fix a few parameters (buffer size, etc)

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Internet

controlledby OS

controlled byapp developer

9/16/2003-9/18/2003

Sockets

Application

Transport

Network

Link

Physical

Socket

9/16/2003-9/18/2003

Addressing

• Need ID for receiving host– Unique 32-bit IP address

9/16/2003-9/18/2003

Addressing

• Need ID for receiving host– Unique 32-bit IP address

• Need to differentiate between processes– Port number (HTTP is typically port 80)

9/16/2003-9/18/2003

Port Number

TCP

Web Server Mail Server

IP = 138.110.1.1

Port = 25Port = 80

9/16/2003-9/18/2003

Transport-layer Services

• Reliability– Do I always need all of my packets to get

there?

• Bandwidth– Do I need a minimum bw guarantee?

• Timing– Can my messages be delayed?

9/16/2003-9/18/2003

App Protocols and Transport Protocols

Application

e-mailremote terminal access

Web file transfer

streaming multimedia

Internet telephony

Applicationlayer protocol

SMTP [RFC 2821]Telnet [RFC 854]HTTP [RFC 2616]FTP [RFC 959]proprietary(e.g. RealNetworks)proprietary(e.g., Dialpad)

Underlyingtransport protocol

TCPTCPTCPTCPTCP or UDP

typically UDP

9/16/2003-9/18/2003

Web and HTTP

• Web page consists of objects– HTML file, JPEG image, Java applet, audio

file,…

• Example– www.mtholyoke.edu/~srollins/

• URL:

www.someschool.edu/someDept/pic.gif

host name path name

9/16/2003-9/18/2003

HTTP Overview

• HTTP: hypertext transfer protocol

• Web’s application layer protocol

• client/server model– client: browser that

requests, receives, “displays” Web objects

– server: Web server sends objects in response to requests

• Server is stateless

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

9/16/2003-9/18/2003

HTTPPC running

Explorer

TCP Open ?

OK

HTTP GET …

Data

TCP Close

9/16/2003-9/18/2003

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

9/16/2003-9/18/2003

Nonpersistent HTTPTCP Open ?

OK

HTTP GET index.htm

Data

TCP Close

TCP Open ?

OK

HTTP GET sami.jpg

Data

TCP Close

9/16/2003-9/18/2003

Response Time Modeling

• RTT – time to send a small packet to travel from client to server and back.

• 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

• Total = 2RTT+transmit time

time to transmit file

initiate TCPconnection

RTT

requestfile

RTT

filereceived

time time

9/16/2003-9/18/2003

Persistent HTTPTCP Open ?

OK

HTTP GET index.htm

Data

HTTP GET sami.jpg

Data

TCP Close

9/16/2003-9/18/2003

Persistent HTTP

Nonpersistent HTTP issues• requires 2 RTTs per object• OS must work and allocate

host resources for each TCP connection

• but browsers often open parallel TCP connections to fetch referenced objects

Persistent HTTP• server leaves connection open

after sending response• subsequent HTTP messages

between same client/server are sent over connection

Persistent without pipelining• client issues new request only

when previous response has been received

• one RTT for each referenced object

Persistent with pipelining• default in HTTP/1.1• client sends requests as soon

as it encounters a referenced object

• as little as one RTT for all the referenced objects

9/16/2003-9/18/2003

HTTP Request Message• two types of HTTP messages: request, response• HTTP request message:

– ASCII (human-readable format)

GET /somedir/page.html HTTP/1.1Host: www.someschool.edu User-agent: Mozilla/4.0Connection: close Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

header lines

Carriage return, line feed

indicates end of message

9/16/2003-9/18/2003

Request General Format

9/16/2003-9/18/2003

Input

POST method• Web page often includes

form input• Input is uploaded to

server in entity body

URL method• Uses GET method• Input is uploaded in URL

field of request line

9/16/2003-9/18/2003

Method Types

HTTP/1.0• GET• POST• HEAD

– asks server to leave requested object out of response

HTTP/1.1• GET, POST, HEAD• PUT

– uploads file in entity body to path specified in URL field

• DELETE– deletes file specified in the

URL field

9/16/2003-9/18/2003

HTTP Response Message

HTTP/1.1 200 OK Connection closeDate: 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 ...

status line(protocol

status codestatus phrase)

header lines

data, e.g., requestedHTML file

9/16/2003-9/18/2003

HTTP Response Status 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

9/16/2003-9/18/2003

User-Server Interaction

• Server may want to identify users– Why?

9/16/2003-9/18/2003

Authorization

• Authorization – control access to

server content

• Credentials– typically name,

password

• Stateless– client must present

authorization in each request

client server

usual http request msg401: authorization req.

WWW authenticate:

usual http request msg

+ Authorization: <cred>usual http response

msg

usual http request msg

+ Authorization: <cred>usual http response

msg

time

9/16/2003-9/18/2003

Cookies

• Four components– 1) cookie header line in

the HTTP response message

– 2) cookie header line in HTTP request message

– 3) cookie file kept on user’s host and managed by user’s browser

– 4) back-end database at Web site

• Example:– Susan access Internet

always from same PC

– She visits a specific e-commerce site for first time

– When initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID

9/16/2003-9/18/2003

Cookies: Exampleclient server

usual http request msgusual http response

+Set-cookie: 1678

usual http request msg

cookie: 1678usual http response

msg

usual http request msg

cookie: 1678usual http response msg

cookie-specificaction

cookie-spectificaction

servercreates ID

1678 for user

entry in backend

database

access

acce

ss

Cookie file

amazon: 1678ebay: 8734

Cookie file

ebay: 8734

Cookie file

amazon: 1678ebay: 8734

one week later:

9/16/2003-9/18/2003

Conditional GET

• Goal: don’t send object if client has up-to-date cached version

• client: specify date of cached copy in HTTP request– If-modified-since:

<date>• server: response

contains no object if cached copy is up-to-date: – HTTP/1.0 304 Not

Modified

client server

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0

304 Not Modified

object not

modified

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0 200 OK

<data>

object modified

9/16/2003-9/18/2003

Assignments

• Finish reading chapter 2 for next week

• Finish up Lab 1

9/16/2003-9/18/2003

FTP

• FTP client contacts FTP server at port 21, specifying TCP as transport protocol

• Client obtains authorization over control connection

• Client browses remote directory by sending commands over control connection.

• When server receives a command for a file transfer, the server opens a TCP data connection to client

• After transferring one file, server closes connection.

FTPclient

FTPserver

TCP control connection

port 21

TCP data connectionport 20

• Server opens a second TCP data connection to transfer another file.

• Control connection: out of band• FTP server maintains “state”:

current directory, earlier authentication

9/16/2003-9/18/2003

Electronic Mail

• Three major components – user agents – mail servers – simple mail transfer

protocol: SMTP

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

9/16/2003-9/18/2003

Example4) SMTP client sends Alice’s

message over the TCP connection

5) Bob’s mail server places the message in Bob’s mailbox

6) Bob invokes his user agent to read message

• 1) Alice uses UA to compose message and “to” [email protected]

• 2) Alice’s UA sends message to her mail server; message placed in message queue

• 3) Client side of SMTP opens TCP connection with Bob’s mail server

useragent

mailserver

mailserver user

agent

1

2 3 4 56

9/16/2003-9/18/2003

Mail Access Protocols

• SMTP: delivery/storage to receiver’s server (push)

• Mail access protocol: retrieval from server– POP: Post Office Protocol

• authorization (agent <-->server) and download – IMAP: Internet Mail Access Protocol

• more features (more complex)• manipulation of stored msgs on server

– HTTP: Hotmail , Yahoo! Mail, etc.

useragent

sender’s mail server

useragent

SMTP SMTP accessprotocol

receiver’s mail server