Bài giảng mạng máy tính và internet chương 2 trần quang hải bằng

22 294 0
Bài giảng mạng máy tính và internet  chương 2   trần quang hải bằng

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chương 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 Office phone: 38962018 Cell phone: N/A Email: bangtqh@hotmail.com Application Layer 24/8-25/10/2009 Chapter The Application Layer Ch2 The Application Layer 2.1 Một số khái niệm 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 The Application Layer 2.1 Một số khái niệm 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 The Application Layer Một số giao thức (application-layer protocols) n HTTP (Hyper Text Transfer Protocol) ¤ n FTP (File Transfer Protocol) ¤ n Giao thức nhận thư điện tử (khác POP3) DNS (Domain Name System) ¤ n Giao thức nhận thư điện tử IMAP (Internet Mail Access Protocol) ¤ n Giao thức truyền thư điện tử POP (Post Office Protocol) ¤ n Giao thức truyền tệp SMTP (Simple Mail Transfer Protocol) ¤ n Giao thức web DNS = hệ thống tên miền, giao thức DNS quy định quy tắc sử dụng tên miền TFTP (Trivial FTP) ¤ Một dạng khác FTP 24/8-25/10/2009 Chapter The Application Layer Net applications vs application-layer protocols n Applications: ¤ ¤ ¤ n Chương trình ứng dụng chạy máy tính Trao đổi thông điệp (message) với ứng dụng khác nhằm thực thi vai trò ứng dụng Vd: web browser, email client… Application-layer protocols: ¤ ¤ ¤ Là thành phần chương trình ứng dụng Định nghĩa quy tắc trao đổi thông điệp Giao tiếp với dịch vụ cung cấp tầng (TCP, UDP) 24/8-25/10/2009 Chapter The Application Layer Các chương trình giao tiếp với ntn? n Các chương trình máy tính ¤ n Các chương trình máy tính khác ¤ n Sử dụng dịch vụ cung cấp hệ điều hành (interprocess communication) Giao tiếp thông qua giao thức tầng ứng dụng (application-layer protocol) 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 giao thức mạng 24/8-25/10/2009 Chapter The Application Layer Mô hình khách-phục vụ (client-server paradigm) Mô hình khách-phục vụ quen gọi mô hình khách-chủ Một ứng dụng application cụ thể bao gồm hai phần: transport n Client ¤ ¤ ¤ ¤ n network data link physical Thiết lập liên kết với server Yêu cầu dịch vụ từ server Nhiều clients Vd: web browser request Server ¤ ¤ ¤ Chờ cung cấp dịch vụ client yêu cầu Thường có server, không thay đổi địa chỉ, chạy 24/7 Vd: web server 24/8-25/10/2009 Chapter The Application Layer reply application transport network data link physical Mô hình ngang hàng (Peer-to-peer paradigm) n n n Không có máy dịch vụ cố định, máy tính mạng lúc server (nhận yêu cầu kết nối) lúc khác lại client (yêu cầu máy khác kết nối) Các máy tính ngang hàng, tự kết nối giao tiếp đôi Địa máy tính tham gia giao tiếp liên tục thay đổi 24/8-25/10/2009 Chapter The Application Layer 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 The Application Layer 10 Dịch vụ tầng application-layer n Có thể coi tầng application (Internet) = tầng application + presentation + session mô hình OSI Các dịch vụ với application: § Presentation: gắn liền với application TCP/IP § § § Session: gắn liền với application TCP/IP § § File formats: picture (JPEG, GIF…), audio (MP3, RM…), video (MPEG, MOV…), document (HTML, XML…) Data encryption & compression 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 UDP 24/8-25/10/2009 Chapter The Application Layer 11 Yêu cầu việc vận chuyển liệu n Data loss ¤ ¤ n Timing ¤ n Các ứng dụng audio/video chấp nhận mát, sai lệch liệu khoảng cho phép Email, file transfer yêu cầu liệu phải xác Các ứng dụng online cần độ trễ (delay) nhỏ (phone, games) 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 The Application Layer 12 Các yêu cầu giao vận số ứng dụng 24/8-25/10/2009 Chapter The Application Layer 13 Internet Transport protocols: TCP & UDP TCP (Transmission Control Protocol) § § § § § connection-oriented: setup required between client, server reliable transport between sending and receiving process flow control: sender won’t overwhelm receiver congestion control: throttle sender when network overloaded does not providing: timing, minimum bandwidth guarantees 24/8-25/10/2009 UDP (User Datagram Protocol) § § unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee Chapter The Application Layer 14 Internet applications: TCP or UDP? 24/8-25/10/2009 Chapter The Application Layer 15 Ch2 The Application Layer 2.1 Một số khái niệm 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 The Application Layer 16 2.2 Web & HTTP n n Trang web (web page): loại tài liệu có chứa nhiều đối tượng: text, image, audio, Java applet, HTML… Về bản, web page = HTML file (base HTML) ¤ ¤ n HTML = Hyper Text Markup Language HTML sử dụng thẻ (tag) để mô tả đối tượng chứa Mỗi đối tượng địa URL (Uniform Resource Locator) ¤ http://www.uct2.edu.vn/ ¤ http://uct2.edu.vn:80/userimages/tqhbang/nhaphoc.jpg Protocol Host name & port Path Chapter The Application Layer 24/8-25/10/2009 17 HTTP (Hyper Text Transfer Protocol) n n Giao thức tầng ứng dụng web Sử dụng mô hình client/server ¤ Client (user agent): n n ¤ Server n n n Trình duyệt web (web browser) Yêu cầu truy cập web thông qua URL (URL request) Máy phục vụ web (web server) Gửi đối tượng tới client thông quan phản hồi (response) HTTP version: ¤ ¤ HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068 24/8-25/10/2009 Chapter The Application Layer 18 HTTP: Quá trình trao đổi thông điệp n n n n Client (browser) thiết lập liên kết tới web server (TCP connection) qua cổng 80 (mặc định) Server đồng ý kết nối (accept) Các thông điệp (HTTP messages) trao đổi browser server Ngắt kết nối 24/8-25/10/2009 Chapter 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 10 hình ảnh jpeg) 1a http client thiết lập liên kết TCP với http server (process) địa www.uct2.edu.vn, cổng 80 (ngầm định với http server) http client gửi http request message (bao gồm URL) tới TCP connection socket time 24/8-25/10/2009 1b http server máy phục vụ www.uct2.edu.vn chờ yêu cầu kết nối TCP cổng 80, chấp nhận kết nối thông báo với client http server nhận request message, tạo http response message có chứa đối tượng yêu cầu gửi vào socket Chapter The Application Layer 20 http server ngắt liên kết 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 10 hình ảnh jpeg tài liệu time Bước 1-5 lặp lại với hình ảnh 24/8-25/10/2009 Chapter The Application Layer 21 HTTP Connection: Persistent & Non-persistent Non-persistent HTTP n Nhiều đối tượng truyền qua liên kết TCP n HTTP 1.0 24/8-25/10/2009 Persistent HTTP n Cho phép nhiều đối tượng truyền liên kết n Client phân tích, tìm gửi yêu cầu tới tất đối tượng sau nhận trang HTML ban đầu (base HTML) n HTTP 1.1 sử dụng liên kết loại chế độ mặc định Chapter The Application Layer 22 HTTP Message Format: request & response n n Hai loại message: request response HTTP request message: dạng ASCII (đọc được!) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg header Accept-language:fr lines Carriage return, line feed indicates end of message 24/8-25/10/2009 (extra carriage return, line feed) Chapter The Application Layer 23 HTTP request message 24/8-25/10/2009 Chapter The Application Layer 24 HTTP response message status line (protocol status code status phrase) header lines HTTP/1.0 200 OK 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 data, e.g., requested html file 24/8-25/10/2009 Chapter The Application Layer 25 HTTP response message 24/8-25/10/2009 Chapter The Application Layer 26 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 The Application Layer 27 Ví dụ thực hành Telnet tới web server: telnet www.uct2.edu.vn 80 Mở kết nối (TCP) tới cổng 80 web server UCT2 Sau kết nối, tất ký tự gõ vào gửi tới cổng 80 Nhập vào GET http request: GET /dangkythilai/help.htm HTTP/1.0 Đây http request đơn giản Nhập xong gõ lần Enter để gửi tới server Kiểm tra kết nhận (http response message)! 24/8-25/10/2009 Chapter The Application Layer 28 User-server interaction: authentication & cookies Authenthication server client usual http request msg 401: authorization req WWW authenticate: usual http request msg + Authorization: usual http response msg time usual http request msg + Authorization: usual http response msg 24/8-25/10/2009 Chapter The Application Layer 29 Cookies: keeping “state” n n Server phát sinh số server (#) client request, client đồng thời ghi nhớ số để 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 usual http request msg quen, lựa chọn truy cập cookiecookie: # lần trước spectific server gửi “cookie” tới usual http response msg action client qua response msg, vd: Set-cookie: 1678453 n Lần sau truy cập website, client gửi kèm cookie, vd: cookie: 1678453 24/8-25/10/2009 usual http request msg cookie: # usual http response msg Chapter The Application Layer cookiespectific action 30 Conditional GET: client-side caching n n MĐ: server không cần gửi client obj tới client client có http request msg phiên cập nhật (up-toIf-modified-since: date) obj Client phải thời gian http response sửa gần obj HTTP/1.0 304 Not Modified http request msg server object not modified If-modified-since: n http request msg Server trả response msg không chứa obj obj cập nhật: If-modified-since: object modified http response HTTP/1.0 304 Not Modified HTTP/1.1 200 OK 24/8-25/10/2009 31 Chapter The Application Layer Web Caches (proxy server) n Client gửi http requests tới web cache thay tới server ¤ ¤ n n Nếu obj có web cache: web cache tạo http response msg gửi cho client Nếu không, web cache tạo gửi http request tới server, nhận obj, lưu trữ, gửi http response msg tới client Web cache khiến người dùng có cảm giác duyệt web nhanh hơn, giảm nghẽn mạng Vd: proxy server IE 24/8-25/10/2009 origin server h tt pr client http Proxy server eq u es t res pon se st ue q e pr nse po ht t s re ht client Chapter The Application Layer es t eq u r p se h tt pon s e pr h tt origin server 32 Why Web Caching? Assume: cache is “close” to client (e.g., in same network) n smaller response time: cache “closer” to client n decrease traffic to distant servers ¤ origin servers public Internet 1.5 Mbps access link institutional network link out of institutional/local ISP network often bottleneck 24/8-25/10/2009 10 Mbps LAN institutional cache Chapter The Application Layer 33 Web servers n IIS (Microsoft Internet Information Server) ¤ ¤ n Apache web server ¤ ¤ ¤ ¤ n Chạy môi trường Windows Đi kèm Windows 2000 Server (IIS 5.0) Mã nguồn mở Linux/Windows… http://www.apache.org Web server dùng nhiều Tomcat, Netscape, Xitami… 24/8-25/10/2009 Chapter The Application Layer 34 Ch2 The Application Layer 2.1 Một số khái niệm 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 Chapter The Application Layer 24/8-25/10/2009 35 Web design: HTML n n Thiết kế web: Tạo tài liệu HTML HTML (Hyper Text Markup Language) ¤ Trong tài liệu HTML có nhiều đối tượng n n n ¤ Sử dụng thẻ (tag) để diễn đạt đối tượng n n n Thẻ mở, vd: ; ; ; … Thẻ đóng, vd: ; ;;… Công cụ: ¤ ¤ ¤ n Text Images Hyper link Text editor: Notepad, Ultra Edit Microsoft FrontPage Macromedia Dreamweaver http://www.w3schools.org (http://www.w3schools.com) 24/8-25/10/2009 Chapter The Application Layer 36 Web programming n n HTML = trang web tĩnh (Static web): Web server trả trang HTML cố định nhận yêu cầu người dùng 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 The Application Layer 37 HTML Form: Send user requests HTML Simple Form 24/8-25/10/2009 ASP Simple ASP [...]... được dùng nhiều nhất Tomcat, Netscape, Xitami… 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 34 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 Chapter 2 The Application Layer 24 /8 -25 /10 /20 09 35 Web design: HTML n n Thiết kế web:... (extra carriage return, line feed) Chapter 2 The Application Layer 23 HTTP request message 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 24 HTTP response message status line (protocol status code status phrase) header lines HTTP/1.0 20 0 OK Date: Thu, 06 Aug 1998 12: 00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 … Content-Length: 6 821 Content-Type: text/html data data data data... HTTP Version Not Supported 24 /8 -25 /10 /20 09 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... Mon, 22 Jun 1998 … Content-Length: 6 821 Content-Type: text/html data data data data data data, e.g., requested html file 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 25 HTTP response message 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 26 HTTP response message: status codes 20 0 OK ¤ request succeeded, requested object later in this message 301 Moved Permanently ¤ requested object moved, new location... để tiếp nhận (cho phép nhiều clients) Microsoft Visual Basic: ¤ Winsock: Windows Socket Component 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 42 Winsock & OSI Chapter 2 The Application Layer 24 /8 -25 /10 /20 09 43 Bài tập n n Tìm hiểu cú pháp ngôn ngữ HTML, từ ñó xây dựng 3 trang web tĩnh page1.htm, page2.htm, page3.htm (nội dung của 3 trang web này tùy theo ý tưởng sáng tạo của mỗi người) Sử dụng một... message)! 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 28 User-server interaction: authentication & cookies Authenthication server client usual http request msg 401: authorization req WWW authenticate: usual http request msg + Authorization: usual http response msg time usual http request msg + Authorization: usual http response msg 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 29 Cookies:... Visual InterDev Chapter 2 The Application Layer 24 /8 -25 /10 /20 09 39 Mô hình 3 lớp trong lập trình web req WEB BROWSER WEB SERVER (Apache, IIS) resp Server-side scripts Các thủ tục truy xuất CSDL CSDL 24 /8 -25 /10 /20 09 ASP, PHP, JSP DB API DB Chapter 2 The Application Layer 40 TCP Socket Programming n n Giao thức HTTP: application-layer protocol Hai ứng dụng application muốn giao tiếp phải sử dụng dịch vụ... time 6 Bước 1-5 được lặp lại với từng hình ảnh 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 21 HTTP Connection: Persistent & Non-persistent Non-persistent HTTP n Nhiều nhất là một đối tượng được truyền qua liên kết TCP n HTTP 1.0 24 /8 -25 /10 /20 09 Persistent HTTP n Cho phép nhiều đối tượng được truyền trên cùng một liên kết 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... Server-side scripts: ASP, JSP, PHP, Perl… 24 /8 -25 /10 /20 09 Chapter 2 The Application Layer 37 HTML Form: Send user requests HTML Simple Form 24 /8 -25 /10 /20 09 ASP ... Chapter 2 The Application Layer 22 HTTP Message Format: request & response n n Hai loại message: request và response HTTP request message: dạng ASCII (đọc được!) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg header Accept-language:fr lines Carriage return, line feed indicates end of message 24 /8 -25 /10 /20 09 (extra ... đổi 24 /8 -2 5 /10 /20 09 Chapter The Application Layer Client-server & P2P examples n CNN.com Client-server n Yahoo! Mail Client-server n Google Client-server n Yahoo! Messenger Client-server & P2P... 12: 00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 … Content-Length: 6 821 Content-Type: text/html data data data data data data, e.g., requested html file 24 /8 -2 5 /10 /20 09... Layer 14 Internet applications: TCP or UDP? 24 /8 -2 5 /10 /20 09 Chapter The Application Layer 15 Ch2 The Application Layer 2. 1 Một số khái niệm nguyên tắc 2. 2 Web & Hyper Text Transfer Protocol 2. 3 Web

Ngày đăng: 04/12/2015, 07:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan