Xem mẫu

  1. Chương 2. Giao th c t ng ng d ng (application layer) Tr n Quang H i B ng Computer Networking and Internet (course of 2009) Faculty of Information Technology University of Communication and Transport (Unit 2) Office location: Administration building, Block D3, Room 6 Office phone: 38962018 Cell phone: N/A Email: bangtqh@hotmail.com Application Layer 24/8-25/10/2009 Chapter 2. The Application Layer 2
  2. Ch2. The Application Layer 2.1. M t s khái ni m và nguyên t c. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and HTTP, Web programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 3 2.1. M t s khái ni m và nguyên t c n M t s chương trình ng d ng (network applications): ¤ Email (Yahoo! Mail, MS Outlook, Google mail,…). ¤ Web browser (MS Internet Explorer, Fire Fox, Netscape Navigator,…). ¤ Instant messenger (Yahoo! Messenger, ICQ, AOL,…). ¤ P2P file sharing (Napster, KazaA…). ¤ Internet games (Yahoo! Games). ¤ Internet telephone (Skype, FPTFone,VNNFone…). ¤ Streaming stored video clips. ¤ Real-time video conference. ¤ Massive parallel computing. 24/8-25/10/2009 Chapter 2. The Application Layer 4
  3. M t s giao th c (application-layer protocols) n HTTP (Hyper Text Transfer Protocol) ¤ Giao th c web. n FTP (File Transfer Protocol) ¤ Giao th c truy n t p. n SMTP (Simple Mail Transfer Protocol) ¤ Giao th c truy n thư đi n t . n POP (Post Office Protocol) ¤ Giao th c nh n thư đi n t . n IMAP (Internet Mail Access Protocol) ¤ Giao th c nh n thư đi n t (khác POP3) n DNS (Domain Name System) ¤ DNS = h th ng tên mi n, giao th c DNS quy đ nh quy t c s d ng tên mi n. n TFTP (Trivial FTP) ¤ M t d ng khác c a FTP. 24/8-25/10/2009 Chapter 2. The Application Layer 5 Net applications vs. application-layer protocols n Applications: ¤ Chương trình ng d ng ch y trên các máy tính. ¤ Trao đ i thông đi p (message) v i các ng d ng khác nh m th c thi vai trò c a ng d ng. ¤ Vd: web browser, email client… n Application-layer protocols: ¤ Là m t thành ph n c a chương trình ng d ng. ¤ Đ nh nghĩa các quy t c trao đ i thông đi p. ¤ Giao ti p v i các d ch v đư c cung c p b i t ng dư i (TCP, UDP). 24/8-25/10/2009 Chapter 2. The Application Layer 6
  4. Các chương trình giao ti p v i nhau ntn? n Các chương trình trên cùng m t máy tính ¤ S d ng các d ch v đư c cung c p b i h đi u hành (interprocess communication). n Các chương trình trên các máy tính khác nhau ¤ Giao ti p thông qua giao th c c a t ng ng d ng (application-layer protocol). n Chương trình phía ngư i dùng = user agent ¤ Giao ti p v i ngư i s d ng (giao di n s d ng). ¤ Giao ti p v i các giao th c m ng. 24/8-25/10/2009 Chapter 2. The Application Layer 7 Mô hình khách-ph c v (client-server paradigm) Mô hình khách-ph c v đư c quen g i là mô hình khách-ch . M t ng d ng c th bao g m hai ph n: application transport network data link physical n Client ¤ Thi t l p liên k t v i server. request ¤ Yêu c u d ch v t server. ¤ Nhi u clients. ¤ Vd: web browser. n Server reply ¤ Ch và cung c p các d ch v khi client yêu c u. application transport ¤ Thư ng ch có 1 server, không thay đ i network data link đ a ch , ch y 24/7. physical ¤ Vd: web server. 24/8-25/10/2009 Chapter 2. The Application Layer 8
  5. Mô hình ngang hàng (Peer-to-peer paradigm) n Không có máy d ch v c đ nh, các máy tính trong m ng lúc này là server (nh n yêu c u k t n i) nhưng lúc khác l i là client (yêu c u máy khác k t n i). n Các máy tính là ngang hàng, t do k t n i và giao ti p đôi m t. n Đ a ch c a các máy tính tham gia giao ti p liên t c thay đ i. 24/8-25/10/2009 Chapter 2. The Application Layer 9 Client-server & P2P examples n CNN.com Client-server n Yahoo! Mail Client-server n Google Client-server n Yahoo! Messenger Client-server & P2P n Internet Relay Chat (IRC) Client-server & P2P 24/8-25/10/2009 Chapter 2. The Application Layer 10
  6. D ch v t ng dư i đ i v i application-layer n Có th coi t ng application (Internet) = t ng application + presentation + session trong mô hình OSI. Các d ch v v i application: § Presentation: g n li n v i application trong TCP/IP § File formats: picture (JPEG, GIF…), audio (MP3, RM…), video (MPEG, MOV…), document (HTML, XML…). § Data encryption & compression. § Session: g n li n v i application trong TCP/IP § NFS (Network File System), RPC (Remote Procedure Call), SQL (Structured Query Language), SSL (Secure Socket Layer). § Transport (*) § Cung c p d ch v v n chuy n cho application (TCP/IP). § Hai giao th c: TCP và UDP. 24/8-25/10/2009 Chapter 2. The Application Layer 11 Yêu c u đ i v i vi c v n chuy n d li u n Data loss ¤ Các ng d ng audio/video có th ch p nh n m t mát, sai l ch d li u trong kho ng cho phép. ¤ Email, file transfer yêu c u d li u ph i chính xác. n Timing ¤ Các ng d ng online c n đ tr (delay) nh (phone, games). n Bandwidth ¤ Các ng d ng multimedia c n đư ng truy n t c đ cao đ đ m b o ch t lư ng. ¤ Các ng d ng email, file transfer m m d o hơn, tuỳ theo t c đ . 24/8-25/10/2009 Chapter 2. The Application Layer 12
  7. Các yêu c u giao v n c a m t s ng d ng 24/8-25/10/2009 Chapter 2. The Application Layer 13 Internet Transport protocols: TCP & UDP TCP (Transmission Control Protocol) UDP (User Datagram Protocol) § connection-oriented: setup § unreliable data transfer required between client, server. between sending and receiving § reliable transport between process sending and receiving process. § does not provide: connection § flow control: sender won’t setup, reliability, flow control, overwhelm receiver. congestion control, timing, or § congestion control: throttle bandwidth guarantee. sender when network overloaded. § does not providing: timing, minimum bandwidth guarantees. 24/8-25/10/2009 Chapter 2. The Application Layer 14
  8. Internet applications: TCP or UDP? 24/8-25/10/2009 Chapter 2. The Application Layer 15 Ch2. The Application Layer 2.1. M t s khái ni m và nguyên t c. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 16
  9. 2.2. Web & HTTP n Trang web (web page): m t lo i tài li u có ch a trong đó nhi u đ i tư ng: text, image, audio, Java applet, HTML… n V cơ b n, web page = HTML file (base HTML). ¤ HTML = Hyper Text Markup Language. ¤ HTML s d ng các th (tag) đ mô t đ i tư ng ch a trong nó. n M i đ i tư ng đư c ch ra b i đ a ch URL (Uniform Resource Locator) ¤ http://www.uct2.edu.vn/ ¤ http://uct2.edu.vn:80/userimages/tqhbang/nhaphoc.jpg Protocol Host name & port Path 24/8-25/10/2009 Chapter 2. The Application Layer 17 HTTP (Hyper Text Transfer Protocol) n Giao th c t ng ng d ng web. n S d ng mô hình client/server. ¤ Client (user agent): n Trình duy t web (web browser) n Yêu c u truy c p web thông qua URL (URL request). ¤ Server n Máy ph c v web (web server). n G i các đ i tư ng t i client thông quan ph n h i (response). n HTTP version: ¤ HTTP 1.0: RFC 1945 ¤ HTTP 1.1: RFC 2068 24/8-25/10/2009 Chapter 2. The Application Layer 18
  10. HTTP: Quá trình trao đ i thông đi p n Client (browser) thi t l p liên k t t i web server (TCP connection) qua c ng 80 (m c đ nh). n Server đ ng ý k t n i (accept). n Các thông đi p (HTTP messages) đư c trao đ i gi a browser và server. n Ng t k t n i. 24/8-25/10/2009 Chapter 2. The Application Layer 19 HTTP example Gi s ngư i dùng truy c p URL: www.uct2.edu/index.html (trang web có text và 10 hình nh jpeg) 1a. http client thi t l p liên k t TCP v i http server (process) 1b. http server t i máy ph c v t i đ a ch www.uct2.edu.vn, www.uct2.edu.vn ch yêu c u c ng 80 (ng m đ nh v i http k t n i TCP t i c ng 80, ch p server). nh n k t n i r i thông báo v i 2. http client g i http request client. message (bao g m c URL) t i TCP connection socket 3. http server nh n request message, t o ra http response message có ch a các đ i tư ng time đư c yêu c u r i g i vào socket. 24/8-25/10/2009 Chapter 2. The Application Layer 20
  11. 4. http server ng t liên k t. 5. http client nh n response message có ch a html file, hi n th html. Sau đó, phân tích html file, tìm URL c a 10 hình nh time jpeg trong tài li u. 6. Bư c 1-5 đư c l p l i v i t ng hình nh. 24/8-25/10/2009 Chapter 2. The Application Layer 21 HTTP Connection: Persistent & Non-persistent Non-persistent HTTP Persistent HTTP n Nhi u nh t là m t đ i n Cho phép nhi u đ i tư ng tư ng đư c truy n qua đư c truy n trên cùng m t liên liên k t TCP. k t. n HTTP 1.0 n Client phân tích, tìm ra và g i yêu c u t i t t c các đ i tư ng ngay sau khi nh n đư c trang HTML ban đ u (base HTML). n HTTP 1.1 s d ng liên k t lo i này ch đ m c đ nh. 24/8-25/10/2009 Chapter 2. The Application Layer 22
  12. HTTP Message Format: request & response n Hai lo i message: request và response. n HTTP request message: d ng ASCII (đ c đư c!) request line (GET, POST, GET /somedir/page.html HTTP/1.0 HEAD commands) User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg header Accept-language:fr lines (extra carriage return, line feed) Carriage return, line feed indicates end of message 24/8-25/10/2009 Chapter 2. The Application Layer 23 HTTP request message 24/8-25/10/2009 Chapter 2. The Application Layer 24
  13. HTTP response message status line (protocol status code HTTP/1.0 200 OK status phrase) Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... header Content-Length: 6821 lines Content-Type: text/html data data data data data ... data, e.g., requested html file 24/8-25/10/2009 Chapter 2. The Application Layer 25 HTTP response message 24/8-25/10/2009 Chapter 2. The Application Layer 26
  14. HTTP response message: 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 24/8-25/10/2009 Chapter 2. The Application Layer 27 Ví d th c hành 1. Telnet t i web server: telnet www.uct2.edu.vn 80 M m t k t n i (TCP) t i c ng 80 t i web server c a UCT2. Sau khi k t n i, t t c ký t gõ vào s đư c g i t i c ng 80. 2. Nh p vào GET http request: GET /dangkythilai/help.htm HTTP/1.0 Đây là m t http request đơn gi n. Nh p xong gõ 2 l n Enter đ g i t i server 3. Ki m tra k t qu nh n đư c (http response message)! 24/8-25/10/2009 Chapter 2. The Application Layer 28
  15. User-server interaction: authentication & cookies Authenthication client server usual http request msg 401: authorization req. WWW authenticate: usual http request msg + Authorization: usual http response msg usual http request msg + Authorization: time usual http response msg 24/8-25/10/2009 Chapter 2. The Application Layer 29 Cookies: keeping “state” n Server phát sinh m t con s nào đó (#) khi client request, client server đ ng th i ghi nh s này đ usual http request msg s d ng sau này: usual http response + ¤ Ch ng th c Set-cookie: # (authentication) ¤ Ghi nh s thích, thói quen, l a ch n truy c p usual http request msg cookie: # cookie- l n trư c. spectific n server g i “cookie” t i usual http response msg action client qua response msg, vd: Set-cookie: 1678453 usual http request msg n L n sau truy c p website, cookie- cookie: # client g i kèm cookie, vd: spectific cookie: 1678453 usual http response msg action 24/8-25/10/2009 Chapter 2. The Application Layer 30
  16. Conditional GET: client-side caching n MĐ: server không c n g i client server obj t i client khi client đã có http request msg phiên b n c p nh t (up-to- If-modified-since: date) c a obj. object not n Client ph i ch ra th i gian modified http response s a g n đây nh t c a obj HTTP/1.0 trong http request msg. 304 Not Modified If-modified-since: n Server s tr v response msg http request msg If-modified-since: không ch a obj n u obj là object c p nh t: modified HTTP/1.0 304 Not Modified http response HTTP/1.1 200 OK 24/8-25/10/2009 Chapter 2. The Application Layer 31 Web Caches (proxy server) n Client g i http requests t i web cache thay vì t i server. ¤ N u obj có t i web cache: web cache t o http response origin server msg g i v cho client. ¤ N u không, web cache t o g i h tt Proxy t pr server ues http request t i server, nh n eq u req client http es t h tt p ons e obj, lưu tr , r i g i http res pon es p pr response msg t i client. se h tt st ue Web cache s khi n ngư i eq nse n pr ht t spo dùng có c m giác duy t web tp re ht nhanh hơn, gi m ngh n m ng. client origin n Vd: proxy server trong IE. server 24/8-25/10/2009 Chapter 2. The Application Layer 32
  17. Why Web Caching? Assume: cache is “close” to origin servers client (e.g., in same public network) Internet n smaller response time: cache “closer” to client 1.5 Mbps n decrease traffic to distant access link servers institutional network 10 Mbps LAN ¤ link out of institutional/local ISP network often bottleneck institutional cache 24/8-25/10/2009 Chapter 2. The Application Layer 33 Web servers n IIS (Microsoft Internet Information Server) ¤ Ch y trên môi trư ng Windows ¤ Đi kèm Windows 2000 Server (IIS 5.0). n Apache web server ¤ Mã ngu n m . ¤ Linux/Windows… ¤ http://www.apache.org ¤ Web server đư c dùng nhi u nh t. n Tomcat, Netscape, Xitami… 24/8-25/10/2009 Chapter 2. The Application Layer 34
  18. Ch2. The Application Layer 2.1. M t s khái ni m và nguyên t c. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and HTTP, Web programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 35 Web design: HTML n Thi t k web: T o ra tài li u HTML n HTML (Hyper Text Markup Language) ¤ Trong tài li u HTML có th có nhi u đ i tư ng n Text n Images n Hyper link ¤ S d ng th (tag) đ di n đ t đ i tư ng. n Th m , vd: ; ; ; … n Th đóng, vd: ; ;;… n Công c : ¤ Text editor: Notepad, Ultra Edit... ¤ Microsoft FrontPage ¤ Macromedia Dreamweaver n http://www.w3schools.org (http://www.w3schools.com) 24/8-25/10/2009 Chapter 2. The Application Layer 36
  19. Web programming n HTML = trang web tĩnh (Static web): Web server luôn tr v m t trang HTML c đ nh khi nh n đư c yêu c u c a ngư i dùng. n L p trình web: tương tác v i ngư i s d ng thông qua web. ¤ L p trình web # L p trình Pascal, C: n Tương tác thông qua HTTP Message. ¤ Client-side scripts: Java script, VB script. ¤ Server-side scripts: ASP, JSP, PHP, Perl… 24/8-25/10/2009 Chapter 2. The Application Layer 37 HTML Form: Send user requests HTML ASP Simple Form Simple ASP
  20. ASP (Active Server Page) n Microsoft/IIS. n M t tài li u ASP có th coi như m t tài li u HTML có nhúng các script ASP, đư c ghi l i d ng t p *.asp, đ t t i web server. n M i khi đư c request, các script đư c ch y phía server, k t qu tr v client d ng HTML (client không th y source). n Các đ i tư ng: ¤ Request Client request. ¤ Response Server response. ¤ Application ¤ QueryString… n Công c : MS Visual InterDev 24/8-25/10/2009 Chapter 2. The Application Layer 39 Mô hình 3 l p trong l p trình web req WEB BROWSER WEB SERVER (Apache, IIS) resp Server-side scripts ASP, PHP, JSP Các th t c truy xu t CSDL DB API CSDL DB 24/8-25/10/2009 Chapter 2. The Application Layer 40
nguon tai.lieu . vn