Xem mẫu

  1. Chương 2 (ti p). 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 Discussion Web programming with ASP. Visual Basic programming. § Object oriented programming. § Event driven programming. § Component driven programming. TCP Socket programming. § Simple web server. 24/8-25/10/2009 Chapter 2. The Application Layer 2
  2. Winsock 24/8-25/10/2009 Chapter 2. The Application Layer 3 HTTP example Gi s ngư i dùng truy c p URL: www.uct2.edu.vn/index.htm (trang web có text và 10 hình nh jpeg) 0. http server t i máy ph c v 1a. http client thi t l p liên k t www.uct2.edu.vn ch yêu c u TCP v i http server (process) k t n i TCP t i c ng 80. t i đ a ch www.uct2.edu.vn, c ng 80 (ng m đ nh v i http server). 1b. http server ch p nh n k t n i r i thông báo v i client. 2. http client g i http request message (bao g m c URL) t i TCP connection socket 3. http server nh n request message, t o ra http response time message có ch a các đ i tư ng đư c yêu c u r i g i vào socket. 24/8-25/10/2009 Chapter 2. The Application Layer 4
  3. 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 5 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 6
  4. 2.4. FTP - File Transfer Protocol FTP file transfer FTP FTP user client server interface user at host local file remote file system system n Truy n/t i t p (to/from remote host). n Client/server model ¤ Client: đưa ra yêu c u truy n t i. ¤ Server = remote host. n FTP: RFC 959 24/8-25/10/2009 Chapter 2. The Application Layer 7 FTP: control & data connections TCP control connection port 21 TCP data connection FTP port 20 FTP n FTP s d ng TCP. client server n FTP s d ng đ ng th i 2 liên k t TCP t i 2 c ng: ¤ TCP control connection, port 21: trao đ i các thông đi p đi u khi n (commands, responses…). ¤ TCP data connection, port 20: truy n t i t p. n FTP lưu gi tr ng thái client trong phiên làm vi c (state vs. HTTP is stateless). 24/8-25/10/2009 Chapter 2. The Application Layer 8
  5. FTP: Quá trình trao đ i/truy n t i TCP control connection port 21 TCP data connection FTP server nghe t i c ng 21. client port 20 server FTP client yêu c u k t n i v i FTP server qua TCP t i c ng 21. G i user & password đ đăng nh p. FTP server ch p nh n, liên k t đi u khi n (control connection) đư c thi t l p. Quá trình trao đ i có th b t đ u. Khi server nh n đư c l nh truy n t p, nó m liên k t d li u (data connection) t i client, t p đư c truy n qua liên k t này. Sau khi truy n xong m t t p, server ng t liên k t d li u (m i liên k t ch s d ng đ truy n m t t p). 24/8-25/10/2009 Chapter 2. The Application Layer 9 FTP commands, responses L nh (commands), phúc đáp (responses) đư c truy n d ng ASCII Sample commands: Sample return codes n sent as ASCII text over control n status code and phrase (as in channel HTTP) n USER username n 331 Username OK, n PASS password password required n LIST return list of file in n 125 data connection already open; current directory transfer starting n RETR filename retrieves n 425 Can’t open data (gets) file connection n STOR filename stores n 452 Error writing (puts) file onto remote host file 24/8-25/10/2009 Chapter 2. The Application Layer 10
  6. FTP clients & servers FTP file transfer FTP FTP user client server interface user at host local file remote file system system n Command-based client: n Microsoft FTP Service ¤ Windows FTP command. n … ¤ Linux FTP command. n GUI clients ¤ Windows Commander. ¤ CuteFTP, WS_FTP… 24/8-25/10/2009 Chapter 2. The Application Layer 11 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 12
  7. 2.5. Electronic Mail Ba thành ph n chính: user agent n User agents (mail clients) mail user ¤ So n, đ c thư (messages). server agent ¤ Vd: Outlook, Eudora, Netscape SMTP mail Messenger... server user n Mail servers SMTP agent ¤ Lưu tr , x lý thư. SMTP ¤ Vd: Exchange, MDeamon… mail user server agent n Protocols ¤ Simple Mail Transfer Protocol (SMTP). user ¤ Post Office Protocol (POP). agent user outgoing ¤ Internet Mail Access Protocol (IMAP). agent message queue ¤ HTTP. user mailbox 24/8-25/10/2009 Chapter 2. The Application Layer 13 Alice Bob 1) Alice s d ng UA so n thư, đ/c g i 4) Mail server c a Alice g i t i “to”: bob@yahoo.com. thư qua liên k t TCP. 2) Alice’s UA g i thư đ n mail server 5) Mail server c a Bob c t thư c a Alice, b c thư đư c x p vào nh n đư c vào hòm thư c a hàng đ i (message queue). Bob. 3) Mail server c a Alice m liên k t 6) Bob dùng UA đ l y thư t TCP t i mail server c a Bob. server v r i đ c thư. 1 mail mail server user user server 2 agent agent 3 6 4 5 Outlook Yahoo! Mail uct2.edu.vn yahoo.com 24/8-25/10/2009 Chapter 2. The Application Layer 14
  8. SMTP (Simple Mail Transfer Protocol) n S d ng liên k t TCP (port 25) đ g i mails: ¤ T sender’s mail client t i sender’s mail server. ¤ T sender’s mail server t i receiver’s mail server. n Ba pha (three ways handshake): ¤ B t tay (handshaking/greeting). ¤ Trao đ i messages. ¤ K t thúc. n Command/response: ¤ commands: ASCII. ¤ responses: status code & phrase. 24/8-25/10/2009 Chapter 2. The Application Layer 15 SMTP: sample interaction (C: client; S: server) S: 220 yahoo.com C: HELO uct2.edu.vn S: 250 Hello uct2.edu.vn, pleased to meet you C: MAIL FROM: S: 250 alice@uct2.edu.vn... Sender ok C: RCPT TO: S: 250 bob@yahoo.com ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Hi Bob! C: Would you like to play tennis this evening? C: . S: 250 Message accepted for delivery C: QUIT S: 221 yahoo.com closing connection 24/8-25/10/2009 Chapter 2. The Application Layer 16
  9. SMTP: more n SMTP s d ng persistent connection: m t liên k t, nhi u thông đi p. n Thông đi p (k c n i dung thư) ph i đư c mã hoá d ng ASCII 7 bit (US-ASCII). n Đánh d u k t thúc msg b i CRLF.CRLF n M t s d li u nh phân (vd: picture) có th ch a CRLF.CRLF c n mã hoá đ đ m b o không có d li u nào trùng v i ký hi u k t thúc message (vd: base64). n So sánh v i HTTP: ¤ HTTP: pull protocol SMTP: push protocol. ¤ Cùng s d ng ASCII (command/req/resp/status code). ¤ HTTP: m i obj ch a trong m t msg SMTP: cho phép nhi u obj (text, picture…) trong m t msg (multipart msg). 24/8-25/10/2009 Chapter 2. The Application Layer 17 Mail message format SMTP: giao th c trao đ i email msg (exchange msgs). RFC 822: standard for text message header blank format: line n Header lines, vd: ¤ To: ¤ From: body ¤ Subject: Khác v i smtp commands (MAIL FROM, RCPT TO,…)! n Body ¤ The “message”. ¤ ASCII 24/8-25/10/2009 Chapter 2. The Application Layer 18
  10. MIME (Multipurpose Internet Mail Extension) n RFC 822: text msg, g p khó khăn v i multimedia. n MIME: RFC 2045, RFC 2056. n So v i RFC 822, MIME thêm vào các header lines đ mô t n i dung c a email msg. From: alice@uct2.edu.vn MIME version To: bob@yahoo.com Subject: Picture of yummy crepe. method used MIME-Version: 1.0 to encode data Content-Transfer-Encoding: base64 Content-Type: image/jpeg multimedia data type, subtype, base64 encoded data ..... parameter declaration ......................... ......base64 encoded data encoded data 24/8-25/10/2009 Chapter 2. The Application Layer 19 MIME: Content types Content-type: type/subtype; parameters 24/8-25/10/2009 Chapter 2. The Application Layer 20
  11. MIME: Encoding types Content-Transfer-Encoding: Encoding type 24/8-25/10/2009 Chapter 2. The Application Layer 21 MIME: Multiple objects mail message From: alice@uct2.edu.vn To: bob@yahoo.com Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=StartOfNextPart --StartOfNextPart Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Dear Bob, Please find a picture of a crepe. --StartOfNextPart Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data ..... ......................... ......base64 encoded data --StartOfNextPart 24/8-25/10/2009 Chapter 2. The Application Layer 22
  12. The received mail message n Server thêm vào dòng header m i khi nh n thư: ¤ Received: ¤ Return-path: n Mail có th đư c chuy n qua nhi u server khác nhau (forward). Received: from hamburger.edu by sushi.jp; 12 Oct 98 15:30:01 GMT Received: from crepes.fr by hamburger.edu; 12 Oct 98 15:27:39 GMT 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 24/8-25/10/2009 Chapter 2. The Application Layer 23 Hi n th full headers v i Y! Mail 2.General Preference 1.Mail Options 3.Messages: Show all… 24/8-25/10/2009 Chapter 2. The Application Layer 24
  13. Mail access protocol SMTP SMTP access user user agent protocol agent sender’s mail receiver’s mail server server n SMTP: giao th c g i mail t i server. n Mail access protocol: giao th c nh n mail t server. ¤ POP (Post Office Protocol): RFC 1939. TCP Port 110. ¤ IMAP (Internet Mail Access Protocol): RFC 1730. TCP port 143. ¤ HTTP: Hotmail, Yahoo!... 24/8-25/10/2009 Chapter 2. The Application Layer 25 POP3 protocol [1] Authorization phase S: +OK POP3 server ready n client commands: C: user bob ¤ user: declare username [1] S: +OK ¤ pass: password C: pass hungry n server responses S: +OK user successfully logged on ¤ +OK C: list ¤ -ERR S: 1 498 S: 2 912 S: . [2] Transaction phase, client: C: retr 1 n list: list message numbers [2] S: n retr: retrieve message by number S: . n dele: delete C: dele 1 C: retr 2 [3] Update phase: S: n Quit S: . n nh ng thay đ i (dele) đư c c p nh t C: dele 2 C: quit [3] S: +OK POP3 server signing off 24/8-25/10/2009 Chapter 2. The Application Layer 26
  14. POP3 (more) and IMAP More about POP3 IMAP4 n Ch đ “download and delete” n Lưu tr toàn b msg t i (xem vd trư c): server. ¤ Msg b xoá khi thoát. n Cho phép ngư i dùng t ch c ¤ Không th nh n msg l n n a. lưu tr trên server (t o thư n “Download-and-keep”: m c, di chuy n msg…) ¤ Msg đư c gi l i server. n Lưu tr ng thái gi a các phiên ¤ Có th nh n msg nhi u l n t (state): nhi u client. ¤ Thư m c t t o. n Không lưu tr ng thái gi a các ¤ Các msgs đã di chuy n. phiên làm vi c (stateless). 24/8-25/10/2009 Chapter 2. The Application Layer 27 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 28
  15. 2.6. DNS (Domain Name System) Mr Toan HTTP (Internet Explorer) www.uct2.edu.vn From: N.V.Toan www.uct2.edu.vn => 210.245.22.125 To: Phòng ðT Phòng ðT 210.245.22.125 => D3 DNS client DNS servers Ms Phuong n Đ a ch IP (32 bit) đư c s d ng đ xác đ nh m t nút trong m ng TCP/IP: 210.245.22.125 khó nh ! S d ng tên (host name) song song v i IP address. n DNS (RFC 1034, RFC 1035, RFC 2136): ¤ Chuy n host name IP address. 24/8-25/10/2009 Chapter 2. The Application Layer 29 DNS services DNS không tương tác tr c ti p v i users mà cung c p các d ch v cho các chương trình khác (HTTP, FTP…) thu c t ng ng d ng: n Host name IP (hostname to IP resolve). n Host aliasing. ¤ M t máy tính có tên chính th c và có th có bí danh (alias). n Mail server aliasing. ¤ @uct2.edu.vn mail server address = ? n Load distribution (phân tán t i) ¤ M t d ch v web (cnn.com, yahoo.com…) có th đư c cung c p t i nhi u server có IP khác nhau đ phân tán t i do lư ng ngư i s d ng cao. 24/8-25/10/2009 Chapter 2. The Application Layer 30
  16. Internet domain name space vn n Domain name (tên mi n): n Host name: www.uct2.edu.vn; ¤ Mi n = t p h p các nút m ng có cùng mail.uct2.edu.vn m t nút cha trong sơ đ trên. ¤ vn: Vietnam. ¤ Vd: ¤ edu: education. ¤ uct2.edu.vn; yahoo.com; yale.edu. ¤ uct2: University of Commnication & ¤ Sub-domain: cs.yale.edu; Transport – unit 2. ¤ www: máy ch world wide web. ¤ mail: máy ch mail. 24/8-25/10/2009 Chapter 2. The Application Layer 31 Domain name servers Root DNS Servers com DNS servers org DNS servers edu DNS servers pbs.org poly.edu umass.edu yahoo.com amazon.com DNS servers DNS servers DNS servers DNS servers DNS servers Vd: client mu n bi t IP c a www.amazon.com thì: n Tìm đ a ch c a com DNS servers h i Root DNS servers. n amazon.com com DNS servers. n www.amazon.com amazon.com DNS servers. 24/8-25/10/2009 Chapter 2. The Application Layer 32
  17. DNS: Root name servers a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los k RIPE London (also Amsterdam, Angeles) Frankfurt) d U Maryland College Park, MD g US DoD Vienna, VA i Autonomica, Stockholm (plus 3 h ARL Aberdeen, MD other locations) j Verisign, ( 11 locations) m WIDE Tokyo e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) 13 root name servers b USC-ISI Marina del Rey, CA worldwide l ICANN Los Angeles, CA n Khi local name server không th chuy n host name IP, g i yêu c u t i root srv. n root name server: ¤ Liên l c v i authoritative name server n u chưa th ánh x đ/c ngay. ¤ L y k t qu ánh x g i v t authoritative name server. ¤ Tr k t qu v cho local name server. 24/8-25/10/2009 Chapter 2. The Application Layer 33 TLD and Authoritative Servers n Top-level domain (TLD) servers: ch u trách nhi m v các mi n com, org, net, edu… và uk, fr, ca, jp… ¤ Network Solutions: qu n lý com TLD servers. ¤ Educause: qu n lý edu TLD servers. n Authoritative DNS servers: ¤ M i host trong m ng mu n đư c bi t đ n ph i đư c khai báo v i m t authoritiative DNS server. ¤ DNS servers c a các t ch c ánh x hostname IP cho các hosts c a t ch c đó (vd: web, mail…). ¤ Có th đư c qu n lý b i các t ch c hay nhà cung c p d ch v . 24/8-25/10/2009 Chapter 2. The Application Layer 34
  18. Local name server n Thu c qu n lý c a ISP (ISP, company, university…). n Khi m t host mu n bi t IP c a m t host nào đó, trư c tiên, nó “h i” local name server. n Không nh t thi t ph i n m trong ki n trúc DNS servers (đ c l p). n “G n” máy tính c a ngư i s d ng nh t nên thư ng đư c “h i thăm” đ u tiên m i khi có truy v n DNS. n Xem Windows Local DNS: ipconfig 24/8-25/10/2009 Chapter 2. The Application Layer 35 DNS example 1 root name server Tình hu ng: host surf.eurecom.fr c n đ/c IP c a gaia.cs.umass.edu 2 4 5 3 1. Liên l c v i local DNS server: dns.eurecom.fr 2. dns.eurecom.fr liên l c v i local name server Authorititive root name server (n u c n) dns.eurecom.fr name server dns.umass.edu 3. root name server liên l c v i 1 6 authoritative name server: dns.umass.edu (n u c n) requesting host gaia.cs.umass.edu surf.eurecom.fr 24/8-25/10/2009 Chapter 2. The Application Layer 36
  19. DNS example 2 Root name server có th : root name server 2 6 n Không bi t authoritative 3 7 name server (ans). n Bi t intermediate name server (ins) local name server intermediate name server ¤ T ins có th tìm ra ans dns.eurecom.fr dns.umass.edu 4 5 1 8 authoritative name server dns.cs.umass.edu requesting host surf.eurecom.fr gaia.cs.umass.edu 24/8-25/10/2009 Chapter 2. The Application Layer 37 DNS example 3 root name server recursive query: iterated query n A h i B, B h i C, C h i 2 3 D,… r i tr l i ngư c l i. 4 n Server đư c h i ch u t i 7 n ng g p đôi? local name server intermediate name server dns.eurecom.fr dns.umass.edu iterative query: 5 6 1 8 n DNS server đư c h i g i ý h i m t server khác. authoritative name server dns.cs.umass.edu requesting host n “I don’t know this name, surf.eurecom.fr but ask this server” gaia.cs.umass.edu 24/8-25/10/2009 Chapter 2. The Application Layer 38
  20. DNS: caching & updating n M i khi DNS server nh n đư c yêu c u tra c u IP, IP mà nó tìm đư c s đư c lưu l i ph c v cho nh ng l n tra c u ti p theo. ¤ Timeout: th i gian h t h n (sau m t kho ng th i gian, b n ghi cache tương ng b xoá). ¤ TLD servers thư ng đư c cache t i local name servers. n Cơ ch c p nh t/thông báo đư c đưa ra b i IETF: ¤ RFC 2136 ¤ http://www.ietf.org/html.charters/dnsind-charter.html 24/8-25/10/2009 Chapter 2. The Application Layer 39 DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) n Type=A n Type=CNAME ¤ name = hostname ¤ name = “bí danh” (alias). ¤ value = IP address www.ibm.com ¤ value = tên th t. n Type=NS servereast.backup2.ibm.com ¤ name = domain name ¤ value = IP address c a n Type=MX authoritative name ¤ name = domain name server cho domain này ¤ value = tên c a mail server 24/8-25/10/2009 Chapter 2. The Application Layer 40
nguon tai.lieu . vn