560 likes | 640 Views
Data Communication and Networks. Lecture 3 Application Protocols (HTTP, SMTP,FTP) September 23, 2004. E-mail Web Instant messaging Remote login P2P file sharing Multi-user network games Streaming stored video clips. Internet telephone Real-time video conference
E N D
Data Communication and Networks Lecture 3 Application Protocols (HTTP, SMTP,FTP) September 23, 2004 2: Application Layer
E-mail Web Instant messaging Remote login P2P file sharing Multi-user network games Streaming stored video clips Internet telephone Real-time video conference Massive parallel computing Some network apps 2: Application Layer
Application architectures • Client-server • Peer-to-peer (P2P) • Hybrid of client-server and P2P 2: Application Layer
Client-server archicture 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
Pure P2P architecture • no always on server • arbitrary end systems directly communicate • peers are intermittently connected and change IP addresses • example: Gnutella Highly scalable But difficult to manage 2: Application Layer
Hybrid of client-server and P2P Napster • File transfer P2P • File search centralized: • Peers register content at central server • Peers query same central server to locate content Instant messaging • Chatting between two users is P2P • Presence detection/location centralized: • User registers its IP address with central server when it comes online • User contacts central server to find IP addresses of buddies 2: Application Layer
For a process to receive messages, it must have an identifier A host has a unique32-bit IP address Q: does the IP address of the host on which the process runs suffice for identifying the process? Answer: No, many processes can be running on same host Identifier includes both the IP address and port numbers associated with the process on the host. Example port numbers: HTTP server: 80 Mail server: 25 More on this later Addressing processes 2: Application Layer
Types of messages exchanged, eg, request & response messages Syntax of message types: what fields in messages & how fields are delineated Semantics of the fields, ie, meaning of information in fields Rules for when and how processes send & respond to messages Public-domain protocols: defined in RFCs allows for interoperability eg, HTTP, SMTP Proprietary protocols: eg, KaZaA App-layer protocol defines 2: Application Layer
Data loss some apps (e.g., audio) can tolerate some loss other apps (e.g., file transfer, telnet) require 100% reliable data transfer Timing some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” What transport service does an app need? Bandwidth • some apps (e.g., multimedia) require minimum amount of bandwidth to be “effective” • other apps (“elastic apps”) make use of whatever bandwidth they get 2: Application Layer
Transport service requirements of common apps Time Sensitive no no no yes, 100’s msec yes, few secs yes, 100’s msec yes and no Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Bandwidth elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Data loss no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss 2: Application Layer
www.someschool.edu/someDept/pic.gif path name host name 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: 2: Application Layer
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 HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068 HTTP overview HTTP request PC running Explorer HTTP response HTTP request Server running Apache Web server HTTP response Mac running Navigator 2: Application Layer
Uses TCP: client initiates TCP connection (creates socket) to server, port 80 server accepts TCP connection from client HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed HTTP is “stateless” server maintains no information about past client requests HTTP overview (continued) aside Protocols that maintain “state” are complex! • past history (state) must be maintained • if server/client crashes, their views of “state” may be inconsistent, must be reconciled 2: Application Layer
Stateless vs. Stateful Servers • Stateful • server remembers something about client transactions (control block) • improves efficiency by reducing transport message size • Stateless • server remembers nothing about client transactions • useful when transport protocols may unreliable • servers recover fast from crashes 2: Application Layer
Precise description of stateful server challenge • Idempotent • An operation which can be applied multiple times and still produce the same result • Formally, operation O is idempotent iff • O( a ) = O( O( a ) ) • Example • Idempotent: x = z • Not idempotent: x = x +z • In a stateful server • Request operations must be idempotent, or • The server must recover from failures 2: Application Layer
Comer advice • If the network is unreliable or machines can crash then the server should be stateless • Do you agree? 2: Application Layer
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 HTTP connections 2: Application Layer
Suppose user enters URL www.someSchool.edu/someDepartment/home.index 1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80 Nonpersistent HTTP (contains text, references to 10 jpeg images) 1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time 2: Application Layer
5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects Nonpersistent HTTP (cont.) 4. HTTP server closes TCP connection. time 6.Steps 1-5 repeated for each of 10 jpeg objects 2: Application Layer
HTTP 1.1 Persistent Connections • In previous example, a connection is made for each request. This is bad. Why? • TCP 3-way hand-shake • TCP slow start • In http 1.1, persistent connections were added as default behavior. • Connection stays open unless client or server specify close when request satisfied: • Header = Connection: close 2: Application Layer
HTTP 1.1 Pipelining • Persistent connection improves performance some, but connection half session is still under-utilized. • Client sends request, then waits for response • Server sends response, the waits for new request • Pipelining - send next request before previous response is received. • Studies show that persistent connections alone perform poorly. Pipelining improves performance considerably. 2: Application Layer
HTTP request message • two types of HTTP messages: request, response • HTTP request message: • ASCII (human-readable format) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.1 Host: www.someschool.edu User-agent: Mozilla/4.0 Connection: close Accept-language:fr (extra carriage return, line feed) header lines Carriage return, line feed indicates end of message 2: Application Layer
HTTP request message: general format 2: Application Layer
HTTP Request Methods • First word in HTTP request is method • HTTP 1.1 methods are: • GET (retrieve a resource) • HEAD (retrieve info about resource) • POST (submit an html form) • PUT (create/modify resources) • DELETE (delete a resource) • TRACE (trace requests in proxy chains) • OPTIONS (request for settings from proxy or server) 2: Application Layer
HTTP response message status line (protocol status code status phrase) HTTP/1.1 200 OK Connection close Date: 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 ... header lines data, e.g., requested HTML file 2: Application Layer
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 HTTP response status codes In first line in server->client response message. A few sample codes: 2: Application Layer
1. Telnet to your favorite Web server: Trying out HTTP (client side) for yourself Opens TCP connection to port 80 (default HTTP server port) at cis.poly.edu. Anything typed in sent to port 80 at cis.poly.edu telnet cis.poly.edu 80 2. Type in a GET HTTP request: By typing this in (hit carriage return twice), you send this minimal (but complete) GET request to HTTP server GET /~ross/ HTTP/1.1 Host: cis.poly.edu 3. Look at response message sent by HTTP server! 2: Application Layer
HTTP State Management: Cookies • We said earlier that HTTP is a stateless protocol • We also said that stateful protocols can provide improved performance. This feature is usually established by the idea of a “session” between client and server. • So, how can we get sessions in HTTP? • COOKIES! 2: Application Layer
COOKIES (briefly) • Cookie protocol - RFC 2109 • A cookie is a token given to a client by a server. • Server sends Set-cookie: header in response • Client associates cookie with issuing server (directory) • The token is just a file with a simple format (name/value pairs) • Each cookie has a unique name 2: Application Layer
server sends “cookie” to client in response mst Set-cookie: 1678453 client presents cookie in later requests cookie: 1678453 server matches presented-cookie with server-stored info authentication remembering user preferences, previous choices usual http request msg cookie: # usual http request msg cookie: # usual http response msg usual http response msg Client-server interaction: cookies server client usual http request msg usual http response + Set-cookie: # cookie- spectific action cookie- spectific action 2: Application Layer
Cookie example 1. User Agent -> Server POST /acme/login HTTP/1.1 [form data] User identifies self via a form. 2. Server -> User Agent HTTP/1.1 200 OK Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme" Cookie reflects user's identity. 3. User Agent -> Server POST /acme/pickitem HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme" [form data] User selects an item for "shopping basket." 2: Application Layer
Cookie example (continued) 4. Server -> User Agent HTTP/1.1 200 OK Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme" Shopping basket contains an item. 5. User Agent -> Server POST /acme/shipping HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"; Part_Number="Rocket_Launcher_0001"; $Path="/acme" [form data] User selects shipping method from form. 2: Application Layer
Cookie example (continued) 6. Server -> User Agent HTTP/1.1 200 OK Set-Cookie: Shipping="FedEx"; Version="1"; Path="/acme" New cookie reflects shipping method. 7. User Agent -> Server POST /acme/process HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"; Part_Number="Rocket_Launcher_0001"; $Path="/acme"; Shipping="FedEx"; $Path="/acme" [form data] User chooses to process order. 8. Server -> User Agent HTTP/1.1 200 OK Transaction is complete. 2: Application Layer
transfer file to/from remote host client/server model client: side that initiates transfer (either to/from remote) server: remote host ftp: RFC 959 ftp server: port 21 FTP user interface FTP client FTP server local file system FTP: the file transfer protocol file transfer user at host remote file system 2: Application Layer
FTP: Issues • Allow transfer of arbitrary files • Accommodate different file types • Convert between heterogeneous systems • Data types • Word lengths • Rules for file names • Provide some security (user login) • Permit Interactive or Batch Operation 2: Application Layer
ftp client contacts ftp server at port 21 two parallel TCP connections opened: control: exchange commands, responses between client, server. “out of band control” data: file data to/from server ftp server maintains “state” TCP control connection port 21 TCP data connection port 20 FTP client FTP server FTP: separate control, data connections 2: Application Layer
FTP: Using separate data connections • Separates commands from data • Client can send commands during data transfer • Closed connection indicates end of file • Control connection persists, data connections come and go 2: Application Layer
Sent as ASCII text over control channel USER username PASS password LIST return list of file in current directory RETR filename retrieves (gets) file STOR filename stores (puts) file onto remote host FTP commands 2: Application Layer
FTP return codes • Status code and phrase (as in smtp, http) returned in ASCII over control connection • 331 Username OK, password required • 125 data connection already open; transfer starting • 425 Can’t open data connection • 452 Error writing file 2: Application Layer
Example Protocol Interaction LOCAL COMMANDS BY USER ACTION INVOLVED ftp (host) multics<CR> Connect to host S, port L, establishing control connections. <---- 220 Service ready <CRLF>. username Doe <CR> USER Doe<CRLF>----> <---- 331 User name ok, need password<CRLF>. password mumble <CR> PASS mumble<CRLF>----> <---- 230 User logged in<CRLF>. retrieve (local type) ASCII<CR> (local pathname) test 1 <CR> User-FTP opens local file in ASCII. (for. pathname) test.pl1<CR> RETR test.pl1<CRLF> ----> <---- 150 File status okay; about to open data connection<CRLF>. Server makes data connection to port U. <---- 226 Closing data connection, file transfer successful<CRLF>. type Image<CR> TYPE I<CRLF> ----> <---- 200 Command OK<CRLF> store (local type) image<CR> (local pathname) file dump<CR> User-FTP opens local file in Image. for.pathname) >udd>cn>fd<CR> STOR >udd>cn>fd<CRLF> ----> <---- 550 Access denied<CRLF> terminate QUIT <CRLF> ----> Server closes all connections. 2: Application Layer
Three major components: user agents mail servers simple mail transfer protocol: SMTP User Agent a.k.a. “mail reader” composing, editing, reading mail messages e.g., Eudora, Outlook, elm, Netscape Messenger outgoing, incoming messages stored on server user agent user agent user agent user agent user agent user agent SMTP SMTP SMTP mail server mail server mail server outgoing message queue user mailbox Electronic Mail 2: Application Layer
Mail Servers mailbox contains incoming messages for user messagequeue 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 user agent user agent user agent user agent user agent SMTP SMTP SMTP mail server mail server mail server Electronic Mail: mail servers 2: Application Layer
uses TCP to reliably transfer email message from client to server, port 25 direct transfer: sending server to receiving server three phases of transfer handshaking (greeting) transfer of messages closure command/response interaction commands: ASCII text response: status code and phrase messages must be in 7-bit ASCII Electronic Mail: SMTP [RFC 2821] 2: Application Layer
1) Alice uses UA to compose message and “to” bob@someschool.edu 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 4) 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 user agent user agent mail server mail server Scenario: Alice sends message to Bob 1 2 6 3 4 5 2: Application Layer
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 2: Application Layer
Try SMTP interaction for yourself: • telnet servername 25 • see 220 reply from server • enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) 2: Application Layer
SMTP uses persistent connections SMTP requires message (header & body) to be in 7-bit ASCII SMTP server uses CRLF.CRLF to determine end of message Comparison with HTTP: HTTP: pull SMTP: push both have ASCII command/response interaction, status codes HTTP: each object encapsulated in its own response msg SMTP: multiple objects sent in multipart msg SMTP: final words 2: Application Layer
SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: header lines, e.g., To: From: Subject: differentfrom SMTP commands! body the “message”, ASCII characters only Mail message format header blank line body 2: Application Layer
MIME: multipart Internet mail extension, RFC 2045, 2056 additional lines in msg header declare MIME content type From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data ..... ......................... ......base64 encoded data Message format: multimedia extensions MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data 2: Application Layer
Text : plain, html Image: jpeg, gif Audio: basic, 32kadpcm Video: mpeg, quicktime Application: other data that must be processed by reader before “viewable”. Example subtypes: msword, octet-stream. Multipart: used when sending objects of different types MIME types 2: Application Layer