Mạng máy tính - Chương 2: Giao thức tầng ứng dụng (application layer)

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.

 

ppt43 trang | Chia sẻ: Mr Hưng | Lượt xem: 1132 | Lượt tải: 0download
Bạn đang xem trước 20 trang nội dung tài liệu Mạng máy tính - Chương 2: Giao thức tầng ứng dụng (application layer), để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Chương 2. Giao thức tầng ứng dụng (application layer)Đoàn Thị Thu HàChapter 2. The Application Layer*1-6/2005Application LayerChapter 2. The Application Layer*1-6/2005Ch2. The Application Layer2.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*1-6/20052.1. Một số khái niệm và nguyên tắcMột số chương trình ứng dụng (network applications):Email (Yahoo! Mail, MS Outlook).Web browser (MS Internet Explorer, Netscape Navigator).Instant messenger (Yahoo! Messenger, ICQ).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.Blog (y360 plus, opera, ngoisaoblog..)Chapter 2. The Application Layer*1-6/2005Một số giao thức (application-layer protocols)HTTP (Hyper Text Transfer Protocol)Giao thức web.FTP (File Transfer Protocol)Giao thức truyền tệp.SMTP (Simple Mail Transfer Protocol)Giao thức truyền thư điện tử.POP (Post Office Protocol)Giao thức nhận thư điện tử.IMAP (Internet Mail Access Protocol)Giao thức nhận thư điện tử (khác POP3)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.TFTP (Trivial FTP)Một dạng khác của FTP.Chapter 2. The Application Layer*1-6/2005Net applications vs. application-layer protocolsApplications: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 clientApplication-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).Chapter 2. The Application Layer*1-6/2005Các chương trình giao tiếp với nhau ntn?Các chương trình trên cùng một máy tínhSử dụng các dịch vụ được cung cấp bởi hệ điều hành (interprocess communication).Các chương trình trên các máy tính khác nhauGiao tiếp thông qua giao thức của tầng ứng dụng (application-layer protocol).Chương trình phía người dùng = user agentGiao 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.Chapter 2. The Application Layer*1-6/2005Mô 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:ClientThiế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.ServerChờ và cung cấp các dịch vụ khi client yêu cầu.Thường chỉ có 1 server, không thay đổi địa chỉ, chạy 24/7.Vd: web server.applicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysicalrequestreplyChapter 2. The Application Layer*1-6/2005Mô hình ngang hàng (Peer-to-peer paradigm)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).Các máy tính là ngang hàng, tự do kết nối và giao tiếp đôi một.Địa chỉ của các máy tính tham gia giao tiếp liên tục thay đổi.Chapter 2. The Application Layer*1-6/2005Client-server & P2P examplesCNN.comYahoo! MailGoogleYahoo! MessengerInternet Relay Chat (IRC)eMule, torrentClient-serverClient-serverClient-serverClient-server & P2PClient-server & P2PP2PChapter 2. The Application Layer*1-6/2005Dịch vụ tầng dưới đối với application-layerCó 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/IPFile 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/IPNFS (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.Chapter 2. The Application Layer*1-6/2005Yêu cầu đối với việc vận chuyển dữ liệuData lossCá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.TimingCác ứng dụng online cần độ trễ (delay) nhỏ (phone, games).BandwidthCá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 độ.Chapter 2. The Application Layer*1-6/2005Các yêu cầu giao vận của một số ứng dụngChapter 2. The Application Layer*1-6/2005Internet Transport protocols: TCP & UDPTCP (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.UDP (User Datagram Protocol)unreliable data transfer between sending and receiving processdoes not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee.Chapter 2. The Application Layer*1-6/2005Internet applications: TCP or UDP?Chapter 2. The Application Layer*1-6/2005Ch2. The Application Layer2.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.Chapter 2. The Application Layer*1-6/20052.2. Web & HTTPTrang 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, HTMLVề 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ó.Mỗi đối tượng được chỉ ra bởi địa chỉ URL (Uniform Resource Locator) Protocol Host name & port PathChapter 2. The Application Layer*1-6/2005HTTP (Hyper Text Transfer Protocol)Giao thức tầng ứng dụng web.Sử dụng mô hình client/server.Client (user agent):Trình duyệt web (web browser)Yêu cầu truy cập web thông qua URL (URL request).ServerMáy phục vụ web (web server).Gửi các đối tượng tới client thông quan phản hồi (response).HTTP version:HTTP 1.0: RFC 1945HTTP 1.1: RFC 2068Chapter 2. The Application Layer*1-6/2005HTTP: Quá trình trao đổi thông điệpClient (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) được trao đổi giữa browser và server.Ngắt kết nối.Chapter 2. The Application Layer*1-6/2005HTTP example1a. http client thiết lập liên kết TCP với http server (process) tại địa chỉ www.hau1.edu.vn, cổng 80 (ngầm định với http server).2. http client gửi http request message (bao gồm cả URL) tới TCP connection socket1b. http server tại máy phục vụ www.hau1.edu.vn chờ yêu cầu kết nối TCP tại cổng 80, chấp nhận kết nối rồi thông báo với client.3. http server nhận request message, tạo ra http response message có chứa các đối tượng được yêu cầu rồi gửi vào socket.timeGiả sử người dùng truy cập URL: www.fita.hua.edu.vn/index.htm (trang web có text và 10 hình ảnh jpeg)Chapter 2. The Application Layer*1-6/20055. 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 jpeg trong tài liệu.6. Bước 1-5 được lặp lại với từng hình ảnh.4. http server ngắt liên kết. timeChapter 2. The Application Layer*1-6/2005HTTP Connection: Persistent & Non-persistentNon-persistent HTTPNhiều nhất là một đối tượng được truyền qua liên kết TCP.HTTP 1.0Persistent HTTPCho phép nhiều đối tượng được truyền trên cùng một liên kết.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).HTTP 1.1 sử dụng liên kết loại này ở chế độ mặc định.Chapter 2. The Application Layer*1-6/2005HTTP Message Format: request & responseHai loại message: request và response.HTTP request message: dạng ASCII (đọc được!)GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg Accept-language:fr (extra carriage return, line feed) request line(GET, POST, HEAD commands)header linesCarriage return, line feed indicates end of messageChapter 2. The Application Layer*1-6/2005HTTP request messageChapter 2. The Application Layer*1-6/2005HTTP response messageHTTP/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 ... status line(protocolstatus codestatus phrase)header linesdata, e.g., requestedhtml fileChapter 2. The Application Layer*1-6/2005HTTP response messageChapter 2. The Application Layer*1-6/2005HTTP response message: status codes200 OKrequest succeeded, requested object later in this message301 Moved Permanentlyrequested object moved, new location specified later in this message (Location:)400 Bad Requestrequest message not understood by server404 Not Foundrequested document not found on this server505 HTTP Version Not SupportedChapter 2. The Application Layer*1-6/2005Ví dụ thực hành1. Telnet tới web server:Mở một kết nối (TCP) tới cổng 80 tại web server của trường ĐHNNI. Sau khi kết nối, tất cả ký tự gõ vào sẽ được gửi tới cổng 80.telnet www.hua.edu.vn 802. Nhập vào GET http request:GET /index.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 server3. Kiểm tra kết quả nhận được (http response message)!Chapter 2. The Application Layer*1-6/2005User-server interaction: authentication & cookiesclientserverusual http request msg401: authorization req.WWW authenticate:usual http request msg+ Authorization: usual http response msgusual http request msg+ Authorization: usual http response msgtimeAuthenthicationChapter 2. The Application Layer*1-6/2005Cookies: keeping “state”Server phát sinh một con số nào đó (#) khi client request, đồng thời ghi nhớ số này để sử dụng sau này:Chứng thực (authentication)Ghi nhớ sở thích, thói quen, lựa chọn truy cập lần trước.server gửi “cookie” tới client qua response msg, vd:Set-cookie: 1678453Lần sau truy cập website, client gửi kèm cookie, vd:cookie: 1678453clientserverusual http request msgusual http response +Set-cookie: #usual http request msgcookie: #usual http response msgusual http request msgcookie: #usual http response msgcookie-spectificactioncookie-spectificactionChapter 2. The Application Layer*1-6/2005Conditional GET: client-side cachingMĐ: server không cần gửi obj tới client khi client đã có phiên bản cập nhật (up-to-date) của obj.Client phải chỉ ra thời gian sửa gần đây nhất của obj trong http request msg. If-modified-since: Server sẽ trả về response msg không chứa obj nếu obj là cập nhật: HTTP/1.0 304 Not Modifiedclientserverhttp request msgIf-modified-since: http responseHTTP/1.0 304 Not Modifiedobject not modifiedhttp request msgIf-modified-since: http responseHTTP/1.1 200 OKobject modifiedChapter 2. The Application Layer*1-6/2005Web Caches (proxy server)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 msg gửi về cho client.Nếu không, web cache tạo gửi http request tới server, nhận obj, lưu trữ, rồi gửi http response msg tới client.Web cache sẽ 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 trong IE.clientProxyserverclienthttp requesthttp requesthttp responsehttp responsehttp requesthttp responseorigin serverorigin serverChapter 2. The Application Layer*1-6/2005Why Web Caching?Assume: cache is “close” to client (e.g., in same network)smaller response time: cache “closer” to clientdecrease traffic to distant serverslink out of institutional/local ISP network often bottleneck originserverspublic Internetinstitutionalnetwork10 Mbps LAN1.5 Mbps access linkinstitutionalcacheChapter 2. The Application Layer*1-6/2005Web serversIIS (Microsoft Internet Information Server)Chạy trên môi trường WindowsĐi kèm Windows 2000 Server (IIS 5.0).Apache web serverMã nguồn mở.Linux/Windows server được dùng nhiều nhất.Tomcat, Netscape, XitamiChapter 2. The Application Layer*1-6/2005Ch2. The Application Layer2.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*1-6/2005Web design: HTMLThiết kế web: Tạo ra tài liệu HTMLHTML (Hyper Text Markup Language)Trong tài liệu HTML có thể có nhiều đối tượngTextImagesHyper linkSử dụng thẻ (tag) để diễn đạt đối tượng.Thẻ mở, vd: ; ; ; Thẻ đóng, vd: ; ;;Công cụ:Text editor: Notepad, Ultra Edit...Microsoft FrontPageMacromedia Dreamweaver ( Chapter 2. The Application Layer*1-6/2005Web programmingHTML = 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.Lập trình web: tương tác với người sử dụng thông qua web.LT web # LT Pascal, C:Tương tác thông qua HTTP Message.Client-side scripts: Java script, VB script.Server-side scripts: ASP, JSP, PHP, PerlChapter 2. The Application Layer*1-6/2005HTML Form: Send user requestsSimple Form Simple ASPWelcome " & myName & “!” Response.Write (welcome )%>ASPHTMLChapter 2. The Application Layer*1-6/2005ASP (Active Server Page)Microsoft/IIS.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.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).Các đối tượng:Request  Client request.Response  Server response.ApplicationQueryStringCông cụ: MS Visual InterDevChapter 2. The Application Layer*1-6/2005Mô hình 3 lớp trong lập trình webWEB BROWSERWEB SERVER (Apache, IIS)ASP, PHP, JSPDBreqrespDB APICác thủ tục truy xuất CSDLCSDLServer-side scriptsChapter 2. The Application Layer*1-6/2005TCP Socket ProgrammingGiao thức HTTP: application-layer protocolHai ứng dụng application muốn giao tiếp phải sử dụng dịch vụ của tầng giao vận:Socket: a door between application process and end-end-transport protocol (UCP or TCP).processTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverinternetChapter 2. The Application Layer*1-6/2005TCP Socket: Client/serverServer socket đã mở sẵn và đợi tại một cổng (port) nào đó.Port được sử dụng để chỉ một process cụ thể sử dụng TCP trên một host.Client phải thiết lập kết nối với server (request).Khi server nhận yêu cầu kết nối, nó tạo ra một socket mới để tiếp nhận (cho phép nhiều clients).Microsoft Visual Basic:Winsock: Windows Socket Component.Chapter 2. The Application Layer*1-6/2005Winsock & OSI

Các file đính kèm theo tài liệu này:

  • pptchapter2a_6843.ppt
Tài liệu liên quan