1、2: Application Layer,1,Chapter 2: Application layer,2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS,2.6 P2P file sharing 2.7 Socket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web server,2: Application Layer,2,Chapt
2、er 2: Application Layer,Our goals: conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm,learn about protocols by examining popular application-level protocols HTTP FTP SMTP / POP3 / IMAP DNS programming networ
3、k applications socket API,2: Application Layer,3,Some network apps,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,2: Application Layer,4,Creating a network app,W
4、rite programs that run on different end systems and communicate over a network. e.g., Web: Web server software communicates with browser software little software written for devices in network core network core devices do not run user application code application on end systems allows for rapid app
5、development, propagation,2: Application Layer,5,Chapter 2: Application layer,2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS,2.6 P2P file sharing 2.7 Socket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web server,2:
6、Application Layer,6,Application principles,architectures sockets protocols,2: Application Layer,7,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 comm
7、unicate directly with each other,2: Application Layer,8,Pure P2P architecture,no always-on server arbitrary end systems directly communicate peers are intermittently connected and change IP addresses example: GnutellaHighly scalable but difficult to manage,2: Application Layer,9,Hybrid of client-ser
8、ver and P2P,Skype Internet telephony app Finding address of remote party: centralized server(s) Client-client connection is direct (not through server) Instant messaging Chatting between two users is P2P Presence detection/location centralized: User registers its IP address with central server when
9、it comes online User contacts central server to find IP addresses of buddies,2: Application Layer,10,Processes communicating,Process: program running within a host. within same host, two processes communicate using inter-process communication (defined by OS). processes in different hosts communicate
10、 by exchanging messages,Client process: process that initiates communication Server process: process that waits to be contacted,Note: applications with P2P architectures have client processes & server processes,2: Application Layer,11,Sockets,process sends/receives messages to/from its socket socket
11、 analogous to door sending process shoves message out door sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process,Internet,controlled by OS,controlled by app developer,API: (1) choice of transport protocol; (2) ability to fix a fe
12、w parameters (lots more on this later),2: Application Layer,12,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,13,Addressing proce
13、sses,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? Answer: NO, many processes can be running on same host,identifier includes both IP address and port numbers associated
14、with process on host. Example port numbers: HTTP server: 80 Mail server: 25 to send HTTP message to www.cs.virginia.edu web server: IP address: 128.119.245.12 Port number: 80 more shortly,2: Application Layer,14,App-layer protocol defines,Types of messages exchanged, e.g., request, response Message
15、syntax: what fields in messages & how fields are delineated Message semantics meaning of information in fields Rules for when and how processes send & respond to messages,Public-domain protocols: defined in RFCs allows for interoperability e.g., HTTP, SMTP Proprietary protocols: e.g., KaZaA,2: Appli
16、cation Layer,15,What transport service does an app need?,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”,Bandwidth
17、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,16,Transport service requirements of common apps,Applicationfile transfer e-mail Web documents real-time audio/videostored audio
18、/video interactive games instant messaging,Data lossno loss no loss no loss loss-tolerantloss-tolerant loss-tolerant no loss,Bandwidthelastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic,Time Sensitiveno no no yes, 100s msecyes, few secs yes, 100s msec yes
19、and no,2: Application Layer,17,Internet transport protocols services,TCP service: connection-oriented: setup required between client and server processes reliable transport between sending and receiving process flow control: sender wont overwhelm receiver congestion control: throttle sender when net
20、work overloaded does not provide: timing, minimum bandwidth guarantees,UDP service: unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee Q: why bother? Why is there a UDP?,2: A
21、pplication Layer,18,Internet apps: application, transport protocols,Applicatione-mail remote terminal access Web file transfer streaming multimediaInternet telephony,Application layer protocolSMTP RFC 2821 Telnet RFC 854 HTTP RFC 2616 FTP RFC 959 proprietary (e.g. RealNetworks) proprietary (e.g., Vo
22、nage,Dialpad),Underlying transport protocolTCP TCP TCP TCP TCP or UDPtypically UDP,2: Application Layer,19,Chapter 2: Application layer,2.1 Principles of network applications app architectures app requirements 2.2 Web and HTTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS,2.6 P2P file sharing 2.7 Soc
23、ket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web server,2: Application Layer,20,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 o
24、bjects Each object is addressable by a URL Example URL:,2: Application Layer,21,HTTP overview,HTTP: hypertext transfer protocol Webs application layer protocol client/server model client: browser that requests, receives, “displays” Web objects server: Web server sends objects in response to requests
25、 HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068,PC running Explorer,Server running Apache Web server,Mac running Navigator,HTTP request,HTTP request,HTTP response,HTTP response,2: Application Layer,22,HTTP overview (continued),Uses TCP: client initiates TCP connection (creates socket) to server, port 80 serv
26、er 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,Protocols that maintain “state” are comp
27、lex! past history (state) must be maintained if server/client crashes, their views of “state” may be inconsistent, must be reconciled,aside,2: Application Layer,23,HTTP connections,Nonpersistent HTTP At most one object is sent over a TCP connection. HTTP/1.0 uses nonpersistent HTTP,Persistent HTTP M
28、ultiple objects can be sent over single TCP connection between client and server. HTTP/1.1 uses persistent connections in default mode,2: Application Layer,24,Nonpersistent HTTP,Suppose user enters URL www.someSchool.edu/someDepartment/home.index,1a. HTTP client initiates TCP connection to HTTP serv
29、er (process) at www.someSchool.edu on port 80,2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index,1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connec
30、tion, notifying client,3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket,time,(contains text, references to 10 jpeg images),2: Application Layer,25,Nonpersistent HTTP (cont.),5. HTTP client receives response message contain
31、ing html file, displays html. Parsing html file, finds 10 referenced jpeg objects,6. Steps 1-5 repeated for each of 10 jpeg objects,4. HTTP server closes TCP connection.,time,2: Application Layer,26,Non-Persistent HTTP: Response time,Definition of RTT: time to send a small packet to travel from clie
32、nt 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,2: Application Layer,27,Persistent HTTP,Nonpersistent HTTP issues: requires 2 RTTs per object OS overhead
33、 for each TCP connection 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 sent over open connection,Persistent without pipelining: client issues new reques
34、t 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 object Total Time?,2: Application Layer,28,HTTP request me
35、ssage,two types of HTTP messages: request, response HTTP request message: ASCII (human-readable format),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),request line (GET, POST, HEAD commands),hea
36、derlines,Carriage return, line feed indicates end of message,2: Application Layer,29,HTTP request message: general format,2: Application Layer,30,Uploading form input,Post method: Web page often includes form input Input is uploaded to server in entity body,URL method: Uses GET method Input is uploa
37、ded in URL field of request line:, Application Layer,31,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,2: Application Laye
38、r,32,HTTP response message,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/htmldata data data data data .,status line (protocol status code status phrase),headerlines,data, e.g.
39、, requested HTML file,2: Application Layer,33,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 40
40、4 Not Found requested document not found on this server 505 HTTP Version Not Supported,In first line in server-client response message. A few sample codes:,2: Application Layer,34,Lets look at HTTP in action,telnet example Ethereal example,2: Application Layer,35,HTTP Review,TCP “Stateless” Non-pers
41、istent 44 messages, 22 RTT Persistent 24 messages Non-pipelined 12 RTT Pipelined 3 RTT HTTP Commands (GET, POST, HEAD, etc) HTTP Fields (User-agent, Connection, etc) Telnet as a command-line TCP connection,2: Application Layer,36,Cookies,The need for state: authorization shopping carts recommendatio
42、ns user session state (Web e-mail),Cookies and privacy: cookies permit sites to learn a lot about you you may supply name and e-mail to sites,aside,How to keep “state”: Protocol endpoints: maintain state at sender/receiver over multiple transactions cookies: http messages carry state,2: Application
43、Layer,37,User-server state: cookies,Many major Web sites use cookies Four components: 1) cookie header line of HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on users host, managed by users browser 4) back-end database at Web site,Example: Susan access Intern
44、et 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,2: Application Layer,38,Cookies: keeping “state” (cont.),client,server,usual http request msg,usual http re
45、sponse + Set-cookie: 1678,server creates ID 1678 for user,entry in backend database,2: Application Layer,39,Optimization example,Assumptions average object size = 100,000 bits avg. request rate from institutions browsers to origin servers = 15/sec delay from institutional router to any origin server
46、 and back to router = 2 sec Consequences utilization on LAN = 15% utilization on access link = 100% total delay = Internet delay + access delay + LAN delay= 2 sec + minutes + milliseconds,origin servers,publicInternet,institutional network,10 Mbps LAN,1.5 Mbps access link,institutional cache,2: Appl
47、ication Layer,40,Optimization example (cont),Possible solution increase bandwidth of access link to, say, 10 Mbps Consequences utilization on LAN = 15% utilization on access link = 15% Total delay = Internet delay + access delay + LAN delay= 2 sec + msecs + msecs often a costly upgrade,origin server
48、s,publicInternet,institutional network,10 Mbps LAN,10 Mbps access link,institutional cache,2: Application Layer,41,Optimization example (cont),Install cache suppose hit rate is .4 Consequence 40% requests will be satisfied almost immediately 60% requests satisfied by origin server utilization of acc
49、ess link reduced to 60%, resulting in negligible delays (say 10 msec) total avg delay = Internet delay + access delay + LAN delay = .6*(2.01) secs + .4*milliseconds 1.4 secs,origin servers,publicInternet,institutional network,10 Mbps LAN,1.5 Mbps access link,institutional cache,2: Application Layer,42,Web caches (aka “proxy” server),user sets browser: Web accesses via cache browser sends all HTTP requests to cache object in cache: cache returns object else cache requests object from origin server, then returns object to client,