chapter7a tang ung dung

Upload: lionking90

Post on 06-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Chapter7a Tang Ung Dung

    1/11

    1

    Chng 2.Giao thc tng ng dng (application layer)

    Chapter 2. The Application Layer 2

    Application Layer

    Chapter 2. The Application Layer 3

    Ch2. The Application Layer

    2.1. Mt s khi nim v nguyn tc.

    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 4

    2.1. Mt s khi nim v nguyn tc

    Mt s chng trnh ng dng (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.

  • 8/3/2019 Chapter7a Tang Ung Dung

    2/11

    2

    Chapter 2. The Application Layer 5

    Mt s giao thc (application-layer protocols)

    HTTP (Hyper Text Transfer Protocol) Giao thc web.

    FTP (File Transfer Protocol) Giao thc truyn tp.

    SMTP (Simple Mail Transfer Protocol) Giao thc truyn th in t.

    POP (Post Office Protocol) Giao thc nhn th in t.

    IMAP (Internet Mail Access Protocol) Giao thc nhn th in t (khc POP3)

    DNS (Domain Name System) DNS = h thng tn min, giao thc DNS quy nhquy tc s dngtn min.

    TFTP (Trivial FTP) Mt dngkhc ca FTP.

    Chapter 2. The Application Layer 6

    Net applications vs. application-layer protocols

    Applications: Chng trnh ng dng chy trn

    cc my tnh.

    Trao i thng ip (message) vicc ng dng khcnhm thc thivai tr ca ng dng.

    Vd: web browser, email client

    Application-layer protocols: L mt thnh phn ca chng

    trnh ng dng.

    nh ngha cc quy tc trao ithng ip.

    Giao tip vi cc dch v ccung cp bi tng di (TCP,UDP).

    Chapter 2. The Application Layer 7

    Cc chng trnh giao tip vi nhau ntn?

    Cc chng trnh trn cng mt my tnhS dng cc dch v c cung cp bi h iu hnh

    (interprocess communication).

    Cc chng trnh trn cc my tnh khc nhauGiao tip thng qua giao thc ca tng ng dng

    (application-layer protocol).

    Chng trnh pha ngi dng = user agentGiao tip vi ngi s dng (giao din s dng).

    Giao tip vi cc giao thc mng.

    Chapter 2. The Application Layer 8

    M hnh khch-phc v (client-server paradigm)

    M hnh khch-phc v c quen gil m hnh khch-ch. Mtng dngc thbao gm hai phn:

    Client Thit lplin kt vi server. Yu cu dch v t server. Nhiu clients. Vd: web browser.

    Server Chvcung cpcc dch v khi client

    yu cu. Thngch c 1 server, khng thay i

    a ch, chy 24/7. Vd: web server.

    applicationtransportnetworkdata linkphysical

    applicationtransportnetworkdata linkphysical

    request

    reply

  • 8/3/2019 Chapter7a Tang Ung Dung

    3/11

    3

    Chapter 2. The Application Layer 9

    M hnh ngang hng (Peer-to-peer paradigm)

    Khng c my dch v c nh,cc my tnh trong mng lcny l server (nhn yu cu ktni) nhng lc khc li l client(yu cu my khc kt ni).

    Cc my tnh lngang hng,

    t do kt ni v giao tip i

    mt. a ch ca cc my tnh tham

    gia giao tip lin tc thay i.

    Chapter 2. The Application Layer 10

    Client-server & P2P examples

    CNN.com

    Yahoo! Mail

    Google

    Yahoo! Messenger

    Internet Relay Chat (IRC)

    Client-server

    Client-server

    Client-server

    Client-server & P2P

    Client-server & P2P

    Chapter 2. The Application Layer 11

    Dch v tng di i vi application-layer

    C th coi tng application (Internet) = tng application +presentation + session trong m hnh OSI.

    Cc dch v vi application: Presentation: gn lin vi application trong TCP/IP

    File formats: picture (JPEG, GIF), audio (MP3, RM), video (MPEG,

    MOV), document (HTML, XML). Data encryption & compression.

    Session: gn lin vi application trong TCP/IP NFS (Network File System), RPC (Remote Procedure Call), SQL

    (Structured Query Language), SSL (Secure Socket Layer).

    Transport (*) Cung cp dch v vn chuyn cho application (TCP/IP). Hai giao thc: TCP v UDP.

    Chapter 2. The Application Layer 12

    Yu cu i vi vic vn chuyn dliu

    Data loss

    Cc ng dng audio/video c th chp nhn mt mt, sai lch dliu trong khong cho php.

    Email, file transfer yu cu d liu phi chnh xc.

    Timing

    Cc ng dng online cn tr (delay) nh (phone, games).

    Bandwidth

    Cc ng dng multimedia cn ng truyn tc cao mbo cht lng.

    Cc ng dng email, file transfer mm do hn, tu theo tc .

  • 8/3/2019 Chapter7a Tang Ung Dung

    4/11

    4

    Chapter 2. The Application Layer 13

    Cc yu cu giao vn ca mt s ng dng

    Chapter 2. The Application Layer 14

    Internet Transport protocols: TCP & UDP

    TCP (Transmission Control Protocol)

    connection-oriented: setuprequired between client, server.

    reliable transportbetweensending and receiving process.

    flow control: sender wontoverwhelm receiver.

    congestion control: throttlesender when networkoverloaded.

    does not providing: timing,minimum bandwidthguarantees.

    UDP (User Datagram Protocol)

    unreliable data transferbetween sending and receivingprocess

    does not provide: connectionsetup, reliability, flow control,congestion control, timing, orbandwidth guarantee.

    Chapter 2. The Application Layer 15

    Internet applications: TCP or UDP?

    Chapter 2. The Application Layer 16

    Ch2. The Application Layer

    2.1. Mt s khi nim v nguyn tc.

    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.

  • 8/3/2019 Chapter7a Tang Ung Dung

    5/11

    5

    Chapter 2. The Application Layer 17

    2.2. Web & HTTP

    Trang web (web page): mt loi ti liu c cha trong nhiu i tng: text, image, audio, Java applet, HTML

    V cbn, web page = HTML file (base HTML).HTML = Hyper Text Markup Language.

    HTML s dng cc th (tag) m t i tng cha trong n.

    Mi i tng c ch ra bi a ch URL (UniformResource Locator)

    http://www.hau1.edu.vn:80/cs/index.htm

    http://www.hau1.edu.vn:80/cs/images/calendar.jpg

    Protocol Host name & port Path

    Chapter 2. The Application Layer 18

    HTTP (Hyper Text Transfer Protocol)

    Giao thc tng ng dng web. S dng m hnh client/server.

    Client (user agent): Trnh duyt web (web browser) Yu cu truycp web thng qua

    URL (URL request).

    Server My phc v web (web server). Gi cc i tng ti client thng

    quan phn hi (response).

    HTTP version:

    HTTP 1.0: RFC 1945

    HTTP 1.1: RFC 2068

    Chapter 2. The Application Layer 19

    HTTP: Qu trnh trao i thng ip

    Client (browser) thit lp lin kt ti web server(TCP connection) qua cng 80 (mc nh).

    Serverng kt ni (accept).

    Cc thng ip (HTTP messages) c trao igia browser v server.

    Ngt kt ni.

    Chapter 2. The Application Layer 20

    HTTP example

    1a. http client thit lplin ktTCP vi http server (process)ti a ch www.hau1.edu.vn,cng 80 (ngm nh vi httpserver).

    2. http client gihttp requestmessage (bao gm c URL) tiTCP connection socket

    1b. http server ti my phc vwww.hau1.edu.vn chyu cu

    kt ni TCP ti cng 80, chpnhn kt ni ri thng bo viclient.

    3. http server nhn requestmessage, to rahttp responsemessage c cha cc i tngc yu cu ri gi vosocket.

    time

    Gi s ngi dng truy cp URL: www.hau1.edu/cs/index.htm

    (trang web c text v 10 hnh nh jpeg)

  • 8/3/2019 Chapter7a Tang Ung Dung

    6/11

    6

    Chapter 2. The Application Layer 21

    5. http client nhn responsemessage c cha html file, hinth html. Sau , phn tch htmlfile, tm URL ca 10 hnh nh

    jpeg trong ti liu.

    6. Bc 1-5 c lp li vi tng

    hnh nh.

    4. http server ngt lin kt.

    time

    Chapter 2. The Application Layer 22

    HTTP Connection: Persistent & Non-persistent

    Non-persistent HTTP

    Nhiu nht l mt itng c truyn qualin kt TCP.

    HTTP 1.0

    Persistent HTTP

    Cho php nhiu i tngc truyn trn cng mt linkt.

    Client phn tch, tm ra v giyu cu ti tt c cc itng ngay sau khi nhn c

    trang HTML ban u (baseHTML).

    HTTP 1.1 s dng lin kt loiny ch mc nh.

    Chapter 2. The Application Layer 23

    HTTP Message Format: request & response

    Hai loi message:request vresponse. HTTP request message: dng ASCII (c c!)

    GET /somedir/page.html HTTP/1.0

    User-agent: Mozilla/4.0Accept: text/html, image/gif,image/jpeg

    Accept-language:fr

    (extra carriage return, line feed)

    request line(GET, POST,

    HEAD commands)header

    lines

    Carriage return,line feed

    indicates endof message

    Chapter 2. The Application Layer 24

    HTTP request message

  • 8/3/2019 Chapter7a Tang Ung Dung

    7/11

    7

    Chapter 2. The Application Layer 25

    HTTP response message

    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 ...

    status line(protocol

    status codestatus phrase)

    headerlines

    data, e.g.,requestedhtml file

    Chapter 2. The Application Layer 26

    HTTP response message

    Chapter 2. The Application Layer 27

    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 inthis 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

    Chapter 2. The Application Layer 28

    V d thc hnh

    1. Telnet ti web server:

    Mmt kt ni (TCP) ti cng 80 ti web server ca trng HDN.Sau khi kt ni, tt c k t gvo s c gi ti cng 80.

    telnet www.ud.edu.vn 80

    2. Nhp vo GET http request:GET /cs/index.htm HTTP/1.0

    y l mthttp request n gin.Nhp xongg 2 ln Enter gi ti server

    3. Kim tra k t qu nhn c (http response message)!

  • 8/3/2019 Chapter7a Tang Ung Dung

    8/11

    8

    Chapter 2. The Application Layer 29

    User-server interaction: authentication & cookies

    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:

    usual http response msgtime

    Authenthication

    Chapter 2. The Application Layer 30

    Cookies: keeping state

    Server pht sinh mt con sno (#) khi client request,ng thi ghi nhs ny s dng sau ny: Chng thc

    (authentication)

    Ghi nhsthch, thiquen, la chn truy cpln trc.

    server gi cookie ti

    client qua response msg, vd:Set-cookie: 1678453

    Ln sau truy cp website,client gi km cookie, vd:cookie: 1678453

    client server

    usual http request msg

    usual http response +Set-cookie: #

    usual http request msgcookie: #

    usual http response msg

    usual http request msgcookie: #

    usual http response msg

    cookie-spectific

    action

    cookie-spectific

    action

    Chapter 2. The Application Layer 31

    Conditional GET: client-side caching

    M: server khng cn giobj ti client khi client cphin bn cp nht (up-to-date) ca obj.

    Client phi ch ra thi giansa gn y nht ca objtrong http request msg.If-modified-since:

    Server s tr v response msgkhng cha obj nu obj lcp nht:HTTP/1.0 304 Not Modified

    client server

    http request msgIf-modified-since:

    http response

    HTTP/1.0304 Not Modified

    objectnot

    modified

    http request msgIf-modified-since:

    http responseHTTP/1.1 200 OK

    objectmodified

    Chapter 2. The Application Layer 32

    Web Caches (proxy server)

    Client gi http requests tiweb cache thay v ti server. Nu obj c ti web cache:

    web cache to http responsemsg gi v cho client.

    Nu khng, web cache to gi

    http request ti server, nhnobj, lu tr, ri gi httpresponse msg ti client.

    Web cache s khin ngidng c cm gic duyt webnhanh hn, gim nghnmng.

    Vd: proxy server trong IE.

    client

    Proxyserver

    client

    httprequest

    http

    reque

    st

    httpresponse

    http

    respon

    se

    httpreque

    st

    httpr

    esponse

    originserver

    originserver

  • 8/3/2019 Chapter7a Tang Ung Dung

    9/11

    9

    Chapter 2. The Application Layer 33

    Why Web Caching?

    Assume: cache is close to

    client (e.g., in same

    network)

    smaller response time:

    cache closer to client

    decrease traffic to distant

    servers

    link out ofinstitutional/local ISP

    network often bottleneck

    originservers

    publicInternet

    institutionalnetwork 10 Mbps LAN

    1.5 Mbpsaccess link

    institutionalcache

    Chapter 2. The Application Layer 34

    Web servers

    IIS (Microsoft Internet Information Server)

    Chy trn mi tr ng Windows

    i km Windows 2000 Server (IIS 5.0).

    Apache web server

    M ngun m.

    Linux/Windows

    http://www.apache.orgWeb serverc dng nhiu nht.

    Tomcat, Netscape, Xitami

    Chapter 2. The Application Layer 35

    Ch2. The Application Layer

    2.1. Mt s khi nim v nguyn tc.

    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 36

    Web design: HTML

    Thit k web: To ra ti liu HTML HTML (Hyper Text Markup Language)

    Trong ti liu HTML c th c nhiu i tng Text

    Images

    Hyper link

    S dng th (tag) din t i tng. Th m, vd: ; ; ; Th ng, vd: ; ;;

    Cng c: Text editor: Notepad, Ultra Edit...

    Microsoft FrontPage

    Macromedia Dreamweaver

    http://www.w3schools.org (http://www.w3schools.com)

  • 8/3/2019 Chapter7a Tang Ung Dung

    10/11

    10

    Chapter 2. The Application Layer 37

    Web programming

    HTML = trang web tnh (Static web): Web serverlun tr v mt trang HTML c nh khi nhn cyu cu ca ngi dng.

    Lp trnh web: tng tc vi ngi s dng thngqua web.

    LT web # LT Pascal, C:

    Tng tc thng qua HTTP Message.Client-side scripts: Java script, VB script.

    Server-side scripts: ASP, JSP, PHP, Perl

    Chapter 2. The Application Layer 38

    HTML Form: Send user requests

    Simple Form

    Simple ASP

  • 8/3/2019 Chapter7a Tang Ung Dung

    11/11

    11

    Chapter 2. The Application Layer 41

    TCP Socket Programming

    Giao thc HTTP: application-layer protocol

    Hai ng dng application mun giao tip phi s dngdch v ca tng giao vn: Socket: a door between application process and end-end-transport

    protocol (UCP or TCP).

    process

    TCP withbuffers,variables

    socket

    controlled byapplicationdeveloper

    controlled byoperating

    system

    host orserver

    process

    TCP withbuffers,variables

    socket

    controlled byapplicationdeveloper

    controlled byoperatingsystem

    host orserver

    internet

    Chapter 2. The Application Layer 42

    TCP Socket: Client/server

    Server socket msn v i ti mt cng (port)no .Port c s dng ch mt process c th s dng

    TCP trn mt host.

    Client phi thit lp kt ni vi server (request).

    Khi server nhn yu cu kt ni, n to r a mt

    socket mi tip nhn (cho php nhiu clients). Microsoft Visual Basic:

    Winsock: Windows Socket Component.

    Chapter 2. The Application Layer 43

    Winsock & OSI