C2 1page Per Sheet

download C2 1page Per Sheet

of 120

Transcript of C2 1page Per Sheet

  • 8/3/2019 C2 1page Per Sheet

    1/120

    Chapter 2Application Layer

    2: Application Layer 1

    Computer Networking:A Top Down Approach,5th edition.

    Jim Kurose, Keith RossAddison-Wesley, April2009.

    A note on the use of these ppt slides:Were making these slides freely available to all (faculty, students, readers).Theyre in PowerPoint form so you can add, modify, and delete slides(including this one) and slide content to suit your needs. They obviouslyrepresent a lotof work on our part. In return for use, we only ask thefollowing: If you use these slides (e.g., in a class) in substantially unaltered form,

    that you mention their source (after all, wed like people to use our book!) If you post any slides in substantially unaltered form on a www site, that

    you note that they are adapted from (or perhaps identical to) our slides, andnote our copyright of this material.

    Thanks and enjoy! JFK/KWR

    All material copyright 1996-2009J.F Kurose and K.W. Ross, All Rights Reserved

  • 8/3/2019 C2 1page Per Sheet

    2/120

    2: Application Layer 2

  • 8/3/2019 C2 1page Per Sheet

    3/120

    Chapter 2: Application layer 2.1 Principles of

    network applications 2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications

    2.7 Socket programmingwith UDP 2.8 Socket programming

    2: Application Layer 3

    . ec ron c a SMTP, POP3, IMAP 2.5 DNS

  • 8/3/2019 C2 1page Per Sheet

    4/120

    Chapter 2: Application LayerOur goals: conceptual,

    implementationaspects of networkapplication protocols

    learn about protocolsby examining popular

    application-levelprotocols HTTP

    2: Application Layer 4

    transport-layerservice models client-server

    paradigm peer-to-peer

    paradigm

    FTP SMTP / POP3 / IMAP DNS

    programming network

    applications socket API

  • 8/3/2019 C2 1page Per Sheet

    5/120

    Some network apps e-mail

    web instant messaging remote login

    social networks

    voice over IP real-time video

    conferencing

    2: Application Layer 5

    P2P file sharing multi-user network

    games

    streaming stored videoclips

    gr compu ng

  • 8/3/2019 C2 1page Per Sheet

    6/120

    To ra mt ng dng mng, ngha l:vit chng trnh sao cho:

    C th chy trn cc host khc

    nhau. C th truyn thng vi nhau qua

    mng

    applicationtransportnetworkdata linkphysical

    2: Application Layer 6

    . .,

    communicates with browsersoftware

    khng cn phi vit cc phnmm chy trn thit b mng(router, switch, ) Cc thit b mng ko chy cc

    apps do ngui dng vit

    Li ny cho php pht trin nhanhcc apps chy trn cc host.

    applicationtransportnetworkdata link

    physical

    applicationtransportnetworkdata linkphysical

  • 8/3/2019 C2 1page Per Sheet

    7/120

    Chapter 2: Application layer 2.1 Principles of

    network applications 2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications

    2.7 Socket programmingwith UDP 2.8 Socket programming

    2: Application Layer 7

    . ec ron c a SMTP, POP3, IMAP 2.5 DNS

  • 8/3/2019 C2 1page Per Sheet

    8/120

    Application architectures Kin trc ng dng l yu t phi quyt nh

    trc tin khi xy dng ng dng mng Client-server

    Including data centers / cloud computing

    2: Application Layer 8

    Peer-to-peer (P2P) Hybrid of client-server and P2P

    Kin trc ng dng kin trc mng (VDInternet c kin trc phn tng!)

  • 8/3/2019 C2 1page Per Sheet

    9/120

    Client-server architectureserver:

    always-on host a ch IP c nh S dng server farms khi ti

    ln

    2: Application Layer 9

    c en s: Truyn thng vi server C th kt ni khng lin

    tc

    C th s dng a ch IPng Khng truyn thng trc

    tip vi nhau.

    client/server

  • 8/3/2019 C2 1page Per Sheet

    10/120

    Google Data Centers Chi ph c tnh ca data center: $600M Google tiu $2.4B trong 2007 cho 1 data

    center mi Mi data center c cng sut 50-100

  • 8/3/2019 C2 1page Per Sheet

    11/120

    Pure P2P architecture Ko dng server

    Cc host truyn thngtrc tip vi nhau Cc peer c th kt ni

    peer-peer

    2: Application Layer 11

    ch IP

    VD: Gnutella ng dngngun m cho php chia

    s file

    C tnh m rng cao nhng

    kh qun l.

  • 8/3/2019 C2 1page Per Sheet

    12/120

    Hybrid of client-server and P2PSkype L ng dng truyn m trn mng IP (VoIP)

    Server trung tm:tm a ch ca bn th 3 Kt ni client-client l trc tip, ko qua Server

    Instant messaging

    2: Application Layer 12

    Dch v centralized service: pht hin/nh v shin din/v tr ca client

    User ng k a ch IP ca n vi server trungtm mi khi online

    User lin lc vi server trung tm tm a chIP ca bn chat.

  • 8/3/2019 C2 1page Per Sheet

    13/120

    Processes communicatingTin trnh (process):

    chng trnh chy trn 1host.

    Trn cng host, 2 tintrnh tru n thn vi

    Tin trnh client : tin trnhkhi to truyn thng

    Tin trnh server: tintrnh ch i c linlc

    2: Application Layer 13

    nhau s dng inter-process communication(c h iu hnh nhngha ).

    Cc tin trnh trn cchost khc nhau truynthng nhau bng trao i

    thng ip (messages)

    Lu : cc ng dng P2P

    c c tin trnh client lntin trnh server.

  • 8/3/2019 C2 1page Per Sheet

    14/120

    Sockets Cc tin trnh gi/nhn cc

    thng ip n/tsocketca n

    Tin trnh~ ngi nh =>~

    process

    socket

    host or

    server

    process

    socket

    host or

    server

    controlled by

    app developer

    2: Application Layer 14

    Tin trnh y thng ip ra

    ca. H tng vn chuyn bn

    ngoi ca chuyn giao thng

    ip ti socket ca tin trnhbn nhn.

    TCP withbuffers,

    variables

    TCP withbuffers,

    variables

    Internet

    controlled

    by OS

    API: (1) choice of transport protocol; (2) ability to fix

    a few parameters (lots more on this later)

  • 8/3/2019 C2 1page Per Sheet

    15/120

    Addressing processes

    nhn thng ip, tintrnh phi c nh danh

    (identifier)

    Cc host u c 1 a ch

    Q:liu a ch IP ca hostm process ang chy trn, c xc nh tin

    trnh? A:Khng , v c c

    nhiutin trnh c th

    2: Application Layer 15

    , .

    Bi tp: dng lnhipconfig t console, ly

    a ch IP trn my tnhWindows.

    . nh danhbao gm c a

    ch IP v s hiu cng (portnumber) c lin kt vi

    tin trnh trn host. V d v cc port number:

    HTTP server: 80

    Mail server: 25

  • 8/3/2019 C2 1page Per Sheet

    16/120

    App-layer protocol defines Cc kiu thng ip c

    trao i, e.g., request, response K php thng ip:

    Cc giao thc cng hu:

    c nh ngha RFCs HTTP: RFC 2616

    Cho php lm vic phi

    2: Application Layer 16

    v m t ca tng field. Ng ngha thng ip

    ngha ca thng tin trntng field

    Cc quy tc v thi imv cch thc cc tintrnh gi v phn hi li

    cc thng ip.

    . e.g., HTTP, SMTP,

    BitTorrentCc giao thc t hu: e.g., Skype, ppstream

  • 8/3/2019 C2 1page Per Sheet

    17/120

    What transport service does an app need?

    Mt d liu Mt s ng dng (VD audio)

    c th chp nhn mt d

    liu. Cc ng dng khc (e.g., file

    transfer, telnet) i hi phi

    Bng thng Vi ng dng (e.g.,

    multimedia) cn bngthng ti thiu t hiuqu.

    Cc n d n khc

    2: Application Layer 17

    tuyt i

    Kp thi Mt s ng dng (e.g.,

    Internet telephony,interactive games) ihi tr thp mcchp nhn c.

    (elastic apps) c th thchnghi vi bng thng hinc (VD email, truyn file,)

    An ton M ha, ton vn d liu,

  • 8/3/2019 C2 1page Per Sheet

    18/120

    Transport service requirements of common apps

    Loi ng dng

    file transfere-mail

    Web documents

    Mt d liu

    no lossno lossno loss

    Bng thng

    elasticelasticelastic

    Kp thi

    nonono

    2: Application Layer 18

    -

    stored audio/videointeractive gamesinstant messaging

    oss- o eran

    loss-tolerantloss-tolerantno loss

    au o: ps- ps

    video:10kbps-5Mbpssame as abovefew kbps upelastic

    ,

    yes, few secsyes, 100s msecyes and no

  • 8/3/2019 C2 1page Per Sheet

    19/120

    Internet transport protocols servicesTCP service: connection-oriented:cn qu trnh

    thit lp kt ni ( handshake)gia cc tin trnh server v client

    Vn chuyn bo m (reliabletransport) gia 2 tin trnh gi v

    UDP service: Vn chuyn thng (ko bo

    m) gia cc tin trnh giv nhn.

    Ko bo m: qu trnh thit

    2: Application Layer 19

    ng ni dung, ko mt gi tin, ko trnggi tin

    ng th t

    flow control:bn gi ko gi qu

    nhanh, lm trn d liu bn nhn congestion control:iu tit tc

    gi d liu khi mng qu ti (kohn tt!).

    Ko bo m: tnh kp thi, bngthng ti thiu, an ninh

    p ng s , v n c uy nm bo, flow control,congestion control, kp thi,bo m bng thng tithiu hay, an ninh

    Q: why bother? Why is therea UDP?

  • 8/3/2019 C2 1page Per Sheet

    20/120

    Internet apps: application, transport protocols

    ng dng

    e-mailremote terminal access

    Web

    Giao thc tngng dng

    SMTP [RFC 2821]Telnet [RFC 854]HTTP [RFC 2616]

    Giao thcvn chuyn

    TCPTCPTCP

    2: Application Layer 20

    e trans erstreaming multimedia

    Internet telephony

    HTTP (eg Youtube),RTP [RFC 1889]SIP, RTP, proprietary(e.g., Skype)

    TCP or UDP

    typically UDP

  • 8/3/2019 C2 1page Per Sheet

    21/120

    Chapter 2: Application layer 2.1 Principles of

    network applications 2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications

    2.7 Socket programmingwith UDP 2.8 Socket programming

    2: Application Layer 21

    . ec ron c a SMTP, POP3, IMAP

    2.5 DNS

  • 8/3/2019 C2 1page Per Sheet

    22/120

    Web and HTTPFirst some jargon

    Trang Web bao gm cc i tng (objects) i tng c th l file HTML, nh JPEG, Java applet,

    file m thanh,

    2: Application Layer 22

    u rang e ao g m e c s aseHTML file) v nhiu i tung c tham chiu

    Mi mt i tung c nh v bng mt URL VD URL:

    www.someschool.edu/someDept/pic.gif

    host name path name

  • 8/3/2019 C2 1page Per Sheet

    23/120

    HTTP overviewHTTP: hypertext transfer

    protocol L giao thc tng ng dngca Web

    HTTP/1.0 (RFC 1945)

    PC runningExplorer

    2: Application Layer 23

    HTTP/1.1 (RFC 2616) M hnh client/server

    client:l trnh duyt(browser) cho php yu cu

    (request), nhn v hin thcc i tng Web. server:Web server gi cc

    i tng n client p

    ng cc yu cu tng ngt client.

    Serverrunning

    Apache Webserver

    Mac runningNavigator

  • 8/3/2019 C2 1page Per Sheet

    24/120

    HTTP overview (continued)Uses TCP: Client khi to kt ni TCP

    (to socket) server, port 80. Server chp nht kt ni TCP

    t pha client

    HTTP is stateless Server khng lu li bt k

    thng tin no v ccrequest t pha client

    2: Application Layer 24

    Trnh duyt v Web Servertrao i cc HTTP messages(chnh l cc message cagiao thc tng ng dng)

    Kt ni TCP c ng.

    Protocols that maintain stateare complex! Thng tin qu kh phi

    c qun l

    Nu lin kt server/client b b, thng tin v trngthi ca 2 pha c th konht qun, cn c iuchnh.

  • 8/3/2019 C2 1page Per Sheet

    25/120

    HTTP connections

    Nonpersistent HTTP Persistent HTTP

    HTTP s dng c 2 cch: nonpersistent connectionhoc persistent connection (mc nh)

    2: Application Layer 25

    Ti a mt object cgi qua kt ni TCP. Nhiu i tng c thc gi qua 1 kt ni

    TCP duy nht giaclient v server

  • 8/3/2019 C2 1page Per Sheet

    26/120

    Nonpersistent HTTPGi s user nhp vo chui URLURL www.someSchool.edu/someDepartment/home.index

    1a. HTTP client khi to kt ni TCPn HTTP server (process) tiwww.someSchool.edu trn port80

    1b. HTTP server ti hostwww.someSchool.edu ch ikt ni TCP connection port

    (trang ny gmtext, tham chiun 10 nh jpeg)

    2: Application Layer 26

    2. HTTP client gi HTTP requestmessage(cha URL) vo socketca kt ni. Message ny ch thrng client mun i tngsomeDepartment/home.index

    80. chp nhn kt ni, bocho client

    3. HTTP server nhn crequest message, hnh thnhnn response messagechacc i tng c yu cu, vgi message no vo socket can.

    time

  • 8/3/2019 C2 1page Per Sheet

    27/120

    Nonpersistent HTTP (cont.)

    5. HTTP client nhn c responeemessage cha file HTML , hinth HTML. Phn tch HTML file,tm ra 10 nh jpeg

    4. HTTP server ng kt ni TCP

    2: Application Layer 27

    6. Bc 1-5 lp li cho mi itng nh jpeg.

    time

  • 8/3/2019 C2 1page Per Sheet

    28/120

    Non-Persistent HTTP: Response timeinh ngha RTT(Round triptime): l thi gian 1 gi

    tin nh i t client nserver v quay tr v.

    Response time: Cn 1 RTT khi to kt

    initiate TCPconnection

    RTT

    2: Application Layer 28

    Cn 1 RTT client gi

    request HTTP v vi byteca HTTP respons tr v

    Thi gian truyn filetotal = 2RTT+transmit time

    time totransmitfile

    reques

    fileRTT

    filereceived

    time time

  • 8/3/2019 C2 1page Per Sheet

    29/120

    Persistent HTTP

    Nonpersistent HTTP issues: Cn 2 RTT cho mi i tng

    Tn chi ph x l ca HHcho tng kt ni TCP Trnh duyt thng phi m

    nhiu kt ni TCP n thi

    Persistent HTTP Server vn duy tr kt ni

    sau khi gi cc phn hi. Cc HTTP message sau

    gia client v server lm victrn cng kt ni ang m.

    2: Application Layer 29

    ti cc i tng Web

    Client gi request ngay khin gp cc i tng. Tn mt RTT cho tt c cc

    i tng c ti.

  • 8/3/2019 C2 1page Per Sheet

    30/120

    HTTP request message Hai kiu thng ip HTTP : request, response

    Thng ip HTTP request: ASCII (human-readable format)

    Dn re uest, m 1

    2: Application Layer 30

    GET /somedir/page.html HTTP/1.1Host: www.someschool.edu

    User-agent: Mozilla/4.0

    Connection: close

    Accept-language:fr

    (extra carriage return,

    line feed)

    trong cc lnh(GET, POST,HEAD)

    Cc dngheader

    Xung hng,Vu dng

    Chth cui thng ip

    Host: ni cha trang webUser-agent: loi browser pht ra

    requestConnection: close=>nonpersistent connectionAccept language: Fr =>cho bituser mun nhn phin bn Phpng ca i tng

  • 8/3/2019 C2 1page Per Sheet

    31/120

    HTTP request message: general format

    2: Application Layer 31

  • 8/3/2019 C2 1page Per Sheet

    32/120

    Uploading form inputPOST method:

    Trang Web thng baogm cc form input Phn d liu ngui

    URL method: S dng GET method

    2: Application Layer 32

    ,

    gn vo phn thn(entity body) ca thngip request v gi v

    cho server

    n u ngudng nhp vo, cgn vo trong field URL dng request

    www.somesite.com/animalsearch?monkeys&banana

  • 8/3/2019 C2 1page Per Sheet

    33/120

    Method typesHTTP/1.0

    GET POST HEAD

    HTTP/1.1

    GET, POST, HEAD PUT

    Upload file c ni dung

    2: Application Layer 33

    Dng cho mc chdebug

    Yu cu server ko cngi i tng v clienttrong thng ip

    response

    ca thng ip request,n ni c ch ra URL field.

    DELETE Xa file c ch ra trong

    URL field

  • 8/3/2019 C2 1page Per Sheet

    34/120

    HTTP response message

    HTTP/1.1 200 OK

    Connection closeDate: Thu, 06 Aug 1998 12:00:15 GMT

    Server: Apache/1.3.0 (Unix)

    -

    Dng trng thi(protocol

    status codestatus phrase)

    cc dng

    2: Application Layer 34

    , ...

    Content-Length: 6821Content-Type: text/html

    data data data data data ...

    header

    d liu, e.g.,requestedHTML file

  • 8/3/2019 C2 1page Per Sheet

    35/120

    HTTP response status codes

    200 OK

    request succeeded, requested object later in this message

    Nm trn dng u tin ca thng ip phn hi t serverMt vi m trng thi:

    2: Application Layer 35

    requested object moved, new location specified later in thismessage (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

  • 8/3/2019 C2 1page Per Sheet

    36/120

    Trying out HTTP (client side) for yourself

    1. Telnet to your favorite Web server:

    Opens TCP connection to port 80(default HTTP server port) at cis.poly.edu.Anything typed in sentto port 80 at cis.poly.edu

    telnet cis.poly.edu 80

    2: Application Layer 36

    2. Type in a GET HTTP request:

    GET /~ross/ HTTP/1.1

    Host: cis.poly.edu

    By typing this in (hit carriagereturn twice), you sendthis minimal (but complete)

    GET request to HTTP server

    3. Look at response message sent by HTTP server!

  • 8/3/2019 C2 1page Per Sheet

    37/120

    User-server state: cookiesMany major Web sites use

    cookies

    Four components:1) cookie header line of

    HTTP responsemessage

    Example: Susan lun truy cp

    Internet t my PC Ln u gh thm site e-

    commerce, c sd cookies

    2: Application Layer 37

    coo e ea er ne n

    HTTP requestmessage3) cookie file kept on

    users host, managed byusers browser

    4) back-end database atWeb site

    Khi e-commnerce serverln u nhn c 1HTTP requests, n to ra: ID duy nht cho Susan

    t my PC. 1 dng trong backend

    database ng vi ID

  • 8/3/2019 C2 1page Per Sheet

    38/120

    Cookies: keeping state (cont.)

    client server

    cookie file

    ebay 8734

    usual http request msg Amazon servercreates ID

    1678 for user createentry

    usual http responseSet-cookie: 1678

    ebay 8734

    2: Application Layer 38

    usual http response msg

    usual http response msg

    Mt tun sau:

    usual http request msgcookie: 1678 cookie-specificaction

    access

    amazon

    usual http request msgcookie: 1678 cookie-

    spectificaction

    accessebay 8734amazon 1678

    backenddatabase

  • 8/3/2019 C2 1page Per Sheet

    39/120

    Cookies (continued)What cookies can bring: authorization shopping carts recommendations

    Cookies and privacy: cookies permit sites to

    learn a lot about you you may supply name

    and e-mail to sites

    aside

    2: Application Layer 39

    e-mail)

    How to keep state: protocol endpoints: maintain state at

    sender/receiver over multipletransactions

    cookies: http messages carry state

  • 8/3/2019 C2 1page Per Sheet

    40/120

    Web caches (proxy server)

    User thit lp trnhduyt: truy cp Webthng qua cache

    Goal: satisfy client request without involving origin server

    Proxyserver

    origin

    server

    2: Application Layer 40

    cc HTTP requests ticache Nu c i tng trong

    cache: cache tr v i

    tng cho trnh duyt Ngc li, cache

    request i tng tserver gc, sau mi

    tr v cho trnh duyt.

    client

    clientoriginserver

  • 8/3/2019 C2 1page Per Sheet

    41/120

    More about Web caching

    Cache hnh x nhclient v nh server

    Thng thng, cachec ISP (trng H,

    Why Web caching?

    Gim thi gian p ngcho cc request t client Gim lu lng ng truy

    2: Application Layer 41

    ,

    phng) thit lp.

    Internet dense with

    caches: enables poorcontent providers to

    effectively deliver content(but so does P2P filesharing)

  • 8/3/2019 C2 1page Per Sheet

    42/120

    Caching exampleGi nh Kch thc bnh qun ca 1 i

    tng web = 1,000,000 bits

    S lng request trung bnh t trnhduyt ca t chc gi n originservers = 15 ln/giy

    originservers

    public

    Internet

    2: Application Layer 42

    ,

    n origin server v quay v lirouter = 2 giy

    H qu Mc s dng Web trn LAN = 15% Mc s dng Web trn access link =

    100% tr tng cng = Internet delay +

    access delay + LAN delay

    = 2 sec + minutes + milliseconds

    institutionalnetwork 100 Mbps LAN

    ps

    access link

    institutionalcache

  • 8/3/2019 C2 1page Per Sheet

    43/120

    Caching example (cont)

    Gii php 1 Tng bng thng access link

    (ng truyn t router ca tchc ra router ca Internet) ln100 Mbps

    originservers

    public

    Internet

    2: Application Layer 43

    Mc s dng Web trn LAN =15% = (15 ln/sec * 1000000bits/ln)/100Mbps=15%

    Mc s dng Web trn accesslink= 15%

    tr tng cng= Internet delay +access delay + LAN delay

    = 2 sec + msecs + msecs Chi ph nng cp ng truyn rt

    t

    institutionalnetwork 100 Mbps LAN

    ps

    access link

    institutionalcache

  • 8/3/2019 C2 1page Per Sheet

    44/120

    Caching example (cont)Gii php kh thi: dng cache Gi s t l p ng ca cache (hit

    rate) l 0.4

    H qu C 40% request s c p ng

    gn nh tc th. C 60% re uest s c ori in

    originservers

    public

    Internet

    2: Application Layer 44

    server p ng.

    Mc s dng Web trn accesslink gim xung cn 60%, dn n tr khng ng k ( khong 10msec trn ng truyn 15 Mbps)

    tr tng cng = Internet delay+ access delay + LAN delay =.6*(2.01) secs + .4*milliseconds p ng chm

    1 DNS Server ko th gntt c cc client => lm gia

    tng cc kt ni ng din DNS => tt nghn. Bo tr 1 DNS cho ton cu!

    ,

    t b danh cho mailserver Phn b ti

    replicated Web servers:s dng nhiu a ch IPng vi mt tn chnhthc.

    Distributed, Hierarchical Database

  • 8/3/2019 C2 1page Per Sheet

    65/120

    Root DNS Servers

    com DNS servers org DNS servers edu DNS servers

    poly.eduDNS servers

    umass.eduDNS servers

    yahoo.comDNS servers

    amazon.com

    pbs.orgDNS servers

    2: Application Layer 65

    Client wants IP for www.amazon.com; 1st approx: Client hi root server tm DNS Server ph trch tn

    min com.

    Client li hi tip DNS Server ph trch tn min com, tm DNS Server ph trch tn min amazon.com

    Client li hi DNS Server ph trch tn min

    amazon.com, ly a ch IP cho www.amazon.com

    DNS: Root name servers

  • 8/3/2019 C2 1page Per Sheet

    66/120

    DNS: Root name servers Khi cc local name server khng th phn gii tn min (do ko lutrong DB), n s lin lc vi root name server root name server:

    Lin lc vi cc authoritative name server v yu cu server ny lo

    dm Nhn kt qu phn gii t authoritative name server Tr kt qu phn gii v local name server

    Recursivequery

    2: Application Layer 66

    13 root nameservers worldwide

    b USC-ISI Marina del Rey, CAl ICANN Los Angeles, CA

    e NASA Mt View, CAf Internet Software C. Palo Alto,CA (and 36 other locations)

    i Autonomica, Stockholm (plus28 other locations)

    k RIPE London (also 16 other locations)

    m WIDE Tokyo (also Seoul,Paris, SF)

    a Verisign, Dulles, VAc Cogent, Herndon, VA (also LA)

    d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 21 locations)

    TLD and Authoritative Servers

  • 8/3/2019 C2 1page Per Sheet

    67/120

    TLD and Authoritative Servers

    Top-level domain (TLD) servers: Chu trch nhim i vi cc tn com, org, net,

    edu, v tt c cc tn min quc gia mc 1 nh uk,fr, ca, vn,

    Network Solutions qun l cc servers dnh cho TLD com

    2: Application Layer 67

    Educause qun l cc servers dnh cho TLD edu

    Authoritative DNS servers: DNS server ca cc t chc, cung cp tt c cc nh

    x tn-a ch IP ca cc server ca t chc (e.g

    Web, mail) Cc DNS Server ny c chnh cc t chc hoc

    nh cung cp dch v qun l.

    Local Name Server

  • 8/3/2019 C2 1page Per Sheet

    68/120

    Local Name Server

    Khng hon ton thuc v H thng DNSc t chc theo cu trc phn cp.

    Mi ISP (ISP a phng, cng ty, trng ihc) u c.

    2: Application Layer 68

    Cng c gi l default name server Khi mt host truy vn DNS, cu hi c gi

    n cho local DNS Server

    Lm vic nh 1 my i din (proxy), chuyn tiptruy vn DNS n h thng phn cp DNS.

    root DNS serverDNS name

  • 8/3/2019 C2 1page Per Sheet

    69/120

    local DNS server

    23

    4

    5

    TLD DNS server

    resolution example Mt host

    cis.poly.edu mun bita ch IP address cagaia.cs.umass.edu

    2: Application Layer 69

    requesting hostcis.poly.edu

    gaia.cs.umass.edu

    dns.poly.edu

    1 6

    authoritative DNS serverdns.cs.umass.edu

    78 iterated query: Server c hi s tr

    li l tn ca servercn hi k tip

    I dont know thisname, but ask thisserver

    root DNS server

    DNS name

  • 8/3/2019 C2 1page Per Sheet

    70/120

    root DNS server

    2

    67TLD DNS server

    3recursive query: t trch nhim phn

    gii tn min honton ln cc serverc hi.

    resolution example

    2: Application Layer 70

    requesting hostcis.poly.edu

    gaia.cs.umass.edu

    local DNS server

    dns.poly.edu

    1

    45

    authoritative DNS server

    dns.cs.umass.edu

    8

    heavy load?

    DNS: caching and updating records

  • 8/3/2019 C2 1page Per Sheet

    71/120

    DNS: caching and updating records

    Mi khi name server c c mapping, n s lucache li mapping ny

    Cc mc cache s ht thi hiu (bin mt) saumt thi gian. TLD Server thn c lu cache t i cc local

    2: Application Layer 71

    name servers Do cc root name server t khi c ving thm.

    C ch cp nht/bo tin uc thc hin theo thitk ca IETF RFC 2136 http://www.ietf.org/html.charters/dnsind-charter.html

    DNS records

  • 8/3/2019 C2 1page Per Sheet

    72/120

    DNS: CSDL phn b, lu cc resource records (RR)

    RR format: (name, value, type, ttl)

    Type=A name l hostname

    Type=CNAME name is b danh ca vi tn

    2: Application Layer 72

    Type=NS name l domain (VD

    foo.com)

    value l hostname caauthoritative name serverdnh cho domain ny

    value l IP address

    chnh thc (canonical name)

    www.ibm.com l b danh caservereast.backup2.ibm.com

    value l tn chnh thc(canonical name)

    Type=MX value l tn ca mailserver

    uc lin kt vi name

    DNS protocol, messages

  • 8/3/2019 C2 1page Per Sheet

    73/120

    p , g

    DNS protocol : quy nh cc query msg v reply msg,c hai c cng nh dng message

    Phn msg header identification: 16 bit #

    for uer , re l to uer

    2: Application Layer 73

    uses same #

    flags: query or reply

    recursion desired

    recursion available reply is authoritative

    DNS protocol, messages

  • 8/3/2019 C2 1page Per Sheet

    74/120

    p , g

    Name, type fieldsfor a query

    RRs in responseto uer

    2: Application Layer 74

    records forauthoritative servers

    additional helpful

    info that may be used

    Inserting records into DNS

  • 8/3/2019 C2 1page Per Sheet

    75/120

    g

    example: new startup Network Utopia register name networkuptopia.com at DNSregistrar

    (e.g., Network Solutions) provide names, IP addresses of authoritative name server(primary and secondary)

    re istrar inserts two RRs into com TLD server:

    2: Application Layer 75

    (networkutopia.com, dns1.networkutopia.com, NS)(dns1.networkutopia.com, 212.212.212.1, A)

    create authoritative server Type A record for

    www.networkuptopia.com; Type MX record fornetworkutopia.com How do people get IP address of your Web site?

    Chapter 2: Application layer

  • 8/3/2019 C2 1page Per Sheet

    76/120

    p pp y

    2.1 Principles ofnetwork applications

    2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications 2.7 Socket programming

    with UDP 2.8 Socket programming

    2: Application Layer 76

    . ec ron c a SMTP, POP3, IMAP

    2.5 DNS

    Pure P2P architecture

  • 8/3/2019 C2 1page Per Sheet

    77/120

    Khng c server ch phc v. Cc host truyn thng trc

    tip Cc peers kt ni nhau khng

    peer-peer

    2: Application Layer 77

    3 trng hp: Phn phi file Tm thng tin Case Study: Skype

    File Distribution: Server-Client vs P2P

  • 8/3/2019 C2 1page Per Sheet

    78/120

    Cu hi: Truyn 1 file t 1 server n N peer mtbao lu?

    Serverus:server uploadbandwidth

    ui:peer i upload

    2: Application Layer 78

    us

    u2d1d2

    u1

    uN

    dNNetwork (with

    abundant bandwidth)

    File, size Fbits

    bandwidth

    di:peer i downloadbandwidth

    File distribution time: server-client

  • 8/3/2019 C2 1page Per Sheet

    79/120

    us

    u2d1 d2u1

    u

    dN

    Server

    Network (withabundant bandwidth)

    F Server ln lt giN bn sao ca file: htNF/us giy

    Client i ti 1 bn sao

    2: Application Layer 79

    mt F/di giy

    Tng tuyn tnh theo N

    (vi N ln)

    = dcs = max { NF/us, F/min(di)}i

    Thi gian chuyn fileF ti N clients s dng cch ti p cnclient/server

    File distribution time: P2P

  • 8/3/2019 C2 1page Per Sheet

    80/120

    us

    u2d1 d2u1

    u

    dN

    Server

    Network (withabundant bandwidth)

    F Server phi gi 1 bn sao

    ca file: ht F/usgiy client i ti file ht F/di giy Tng cng c NF bits

    2: Application Layer 80

    Tc upload (ca ton h thng) nhanhnht c th: us + ui

    dP2P = max { F/us, F/min(di), NF/(us + ui) }i

    Server-client vs. P2P: example

  • 8/3/2019 C2 1page Per Sheet

    81/120

    2.5

    3

    3.5

    tionTime P2P

    Client-Server

    Client upload rate = u, F/u = 1 hour, us = 10u, dmin us

    2: Application Layer 81

    0

    0.5

    1

    1.5

    2

    0 5 10 15 20 25 30 35

    N

    MinimumD

    istribu

    File distribution: BitTorrent

  • 8/3/2019 C2 1page Per Sheet

    82/120

    tracker: theo di cc peers

    ang tham gia vo torrent

    torrent:nhm cc

    peers ang trao icc phn mnh file(chunk of file)

    P2P file distribution

    2: Application Layer 82

    Ly danh sch cc peer

    tradingchunks

    peer

  • 8/3/2019 C2 1page Per Sheet

    83/120

    BitTorrent (1) file c chia thnh cc mnh (chunks)256KB. peer ang tham gia vo torrent:

    cha c mnh no, nhng s tch ly cc chunks

    2: Application Layer 83

    trong sut qu trnh ghi danh vi tracker ( thu danh sch cc peers),

    kt ni ti mt tp con cc peers (lng ging) Trong khi ang download file, peer cng upload cc

    chunks (m n c v c yu cu) cho cc peer khc. peers c th tham gia vo torrent v rt lui. Khi peer c c file, n c th ri torrent (ch k) hoc

    li torrent (v tha)

    BitTorrent (2)

    M1

  • 8/3/2019 C2 1page Per Sheet

    84/120

    Pulling Chunks Ti 1 thi im nht nh,

    cc peer khc nhau ang cc cc chunks khc nhau.

    nh k, mt peer (VD Alice)s hi cc lng ging v danh

    Sending Chunks: tit-for-tat Alice gi cc chunks ti 4

    lng ging m hin thichng ang gi cho Alicecc chunks khc mccao nht.

    2: Application Layer 84

    s ch c c chunks m ch ng

    c. Peer ny (Alice) gi yu cu

    xin cc chunks m n cn

    thiu. u tin xin chunks no m

    t lng ging c nht(rarest first)

    Sau m i 10s, snh

    gi li top 4 ny. Sau mi 30 giy: chn ngu

    nhin peer khc, gi chunk

    cho peer ny. peer mi c chn c

    th tham gia vo top 4

    optimistically unchoke

    Slide 84

    M1 n ming tr mingMVC, 5/1/2010

  • 8/3/2019 C2 1page Per Sheet

    85/120

    BitTorrent: Tit-for-tat

  • 8/3/2019 C2 1page Per Sheet

    86/120

    (1) Alice chn ngu nhin c Bob v gi chunks cho Bob(2) Alice tr thnh mt trong 4 peer gi chunks cho Bobnhiu nht; Bob gi chunks cho Alice p tr.

    (3) Bob tr thnh mt trong 4 peer gi chunk cho Alice nhiu nht.

    2: Application Layer 85

    Cng upload vi tc cao,cng c th tm thy ccpeer trao i chunks d hn& nhn c file nhanh hn.

    Distributed Hash Table (DHT)

  • 8/3/2019 C2 1page Per Sheet

    87/120

    DHT = CSDL phn tn trn mi trng P2P[distributed P2P database] CSDL cha cc cp (key, value);

    key: tn ni dung; value: a ch IP (ni lu ni dung) Peers truy vn CSDL bng cch cung cp tr key

    CSDL tr v gi tr ca value khp vi tr key

    Peers cn c thchn [insert] cc cp (key,value) mi vo CSDL.

    DHT Identifiers

  • 8/3/2019 C2 1page Per Sheet

    88/120

    Mi peer c gn mt s id nh danh, l snguyn nm trong vng [0,2n-1] (n nguyn c nh) Mi id c th c biu din qua chui n bits.

    i hi mi tr ke l m t s n u n thu c cnvng [0,2n-1]

    thu c tr key nguyn nh i hi trn, sdng hm bm h, h nhn tr key gc v tr v trnguyn trong vng [0,2n-1] eg, key = h(Led Zeppelin IV) y l l do ti sao ta gi n l DHT (distributed hash

    table)

    Lu cp (key, value) peer no?

  • 8/3/2019 C2 1page Per Sheet

    89/120

    Vn : Lu tr cp (key, value) peer no? Quy tc: Lu ti peer c id=key. Nu khng

    c peer nh vy th lu ti peer c id gnnht.

    Quy c trong bi ging: id gn nht l idnm lin sau trong danh sch cc id. VD: n=4; peers: 1,3,4,5,8,10,12,14;

    key = 13, th peer lin sau l 14 key = 15, th peer lin sau l 1

    1

    Circular DHT (1)

  • 8/3/2019 C2 1page Per Sheet

    90/120

    1

    3

    415

    5

    810

    12

    Mi peer ch bit peer lin trc v lin sau. Overlay network

    Circle DHT (2)

  • 8/3/2019 C2 1page Per Sheet

    91/120

    0001

    0011

    1111

    Ai chu trch nhim

    cho key 1110 ?L ti

    O(N) messages

    on avg to resolve

    query, when thereare N peers

    0100

    0101

    10001010

    1100

    1110

    1110

    1110

    1110

    1110

    1110

    Define closestas closestsuccessor

    Circular DHT with Shortcuts1 Ai chu trch nhim(0011)

  • 8/3/2019 C2 1page Per Sheet

    92/120

    13

    4

    15

    Ai chu trch nhimcho key 14 (1110) ?

    (1111)

    (0011)

    Mi peer qun l a ch IP ca peer lin trc, peerlin sau v cc short cuts.

    Gim t 6 cn 2 messages. C th thit k shortcuts sao cho s lng ging v

    s message khi truy vn u bng O(log N)

    5

    810

    (1000)

    Peer Churn1

  • 8/3/2019 C2 1page Per Sheet

    93/120

    3

    4

    12

    15

    x l trnh trng cc peer n vi m khng bo trc(peer churn),mi peer cn phi bit cc a chIPca 2 peer lin sau ca n.

    Mi peer s ping nh k 2 peer linsau ca n xc nh l chng cn

    Peer 5 t ngt ri khi vng. Peer 4 pht hin ra iu ny; nhn peer 8 lm peer lin

    sau (th nht); v hi peer 8 peer lin sau ca 8?; sau xem peer lin sau ca 8 l peer k lin sau (thhai)ca n.

    Nu peer 13 mun gia nhp vng th sao?

    810

    .

    P2P Case study: SkypeSkype clients (SC)

  • 8/3/2019 C2 1page Per Sheet

    94/120

    Bn cht P2P: cc cpuser c th truyn thng

    trc tip. Giao thc tng ng dng

    Skype clients (SC)

    Supernode

    SN

    Skypelogin server

    2: Application Layer 93

    .

    T chc phn cp, sdng cc Supernode nh x gia username v

    a ch IP, c lu phn

    b gia cc Supernode.

    Peers as relays Vn gp phi khi c 2

  • 8/3/2019 C2 1page Per Sheet

    95/120

    Vn gp phi khi c 2peer (VD Alice v Bob) unm ng sau NAT NAT ngn chn cc peer t

    bn ngoi khi to cc kt ni(hay cuc gi) n cc peerbn trong

    2: Application Layer 94

    Gii php: S dng cc supernode ca

    Alice v Bob, 1 supernodec chn ra lm relay node(nt chuyn tip)

    Tng peer s khi to kt nivi nt chuyn tip. Do cc peer c th truyn

    thng cho nhau vt qua NATnh nt chuyn tip.

    Chapter 2: Application layer

  • 8/3/2019 C2 1page Per Sheet

    96/120

    2.1 Principles ofnetwork applications

    2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications 2.7 Socket programming

    with UDP 2.8 Socket programming

    2: Application Layer 95

    . ec ron c a SMTP, POP3, IMAP

    2.5 DNS

    Socket programming

    M c tiu: h c cch xy dng ng d ng client/server

  • 8/3/2019 C2 1page Per Sheet

    97/120

    Socket API c gii thiu trong BSD4.1

    UNIX, 1981 A application-created,

    socket

    Mc tiu: hc cch xy dng ng dng client/servertruyn thng vi nhau s dng sockets

    2: Application Layer 96

    c cc ng dng to ra, s

    dng v gii phng mt cchtng minh. client/server paradigm C 2 loi dch v vn chuyn

    thng qua socket API UDP TCP

    -con ro e nter ace

    (a door) into whichapplication process canboth send and

    receive messages to/fromanother application

    process

    Socket programming basics

  • 8/3/2019 C2 1page Per Sheet

    98/120

    Server phi angchy trc khi client

    c th gi d liu chon.

    Socket c th xc nhtrong ni b nh shiu cng(portnumber)

    Server phi c 1socket (ca) m nh n c th nhn/gi i cc segment

    Tng t, client cngcn c 1 socket

    Tng t nh s hiu

    cn h trong 1 ta nh Client cn phi bit a

    ch IP ca Server v s

    hiu cng ca socket.

    2: Application Layer 97

    Socket programming with UDP

  • 8/3/2019 C2 1page Per Sheet

    99/120

    UDP: khng c kt ni giaclient v server

    Khng bt tay Bn gi gn a ch IP v s

    hiu cng ln tng segment

    Quan im ng dng

    UDP cun c dch v vn chu n

    2: Application Layer 98

    Server c t tr c xu t a

    ch IP v s hiu cng cabn gi t segment nhnc.

    datagram khng m bo tin

    cy gia client and server

    Lu : Thut ng chnh thc gi gi

    tin UDP l datagram. Trong lpny chng ta s gi l UDPsegment

    Running example

  • 8/3/2019 C2 1page Per Sheet

    100/120

    Client: Ngi s dng g vo mt dng vn bn Chng trnh client gi dng ny n server

    Server: Server nhn c dng vn bn Server chuyn thnh ch hoa tt c cc k t Gi dng vn bn c sa i n client

    Client: Nhn dng vn bn Hin th

    2: Application Layer 99

    Client/server socket interaction: UDP

    Server (running on h tid) Client

  • 8/3/2019 C2 1page Per Sheet

    101/120

    Server (running on hostid)

    create socket,

    clientSocket =DatagramSocket()

    Client

    T o data ram vi server IP v

    create socket,

    port= x.serverSocket =DatagramSocket()

    2: Application Layer 100

    ngclientSocket

    c datagram tclientSocket

    port=x; gi datagram thng quaclientSocketc datagram t

    serverSocket

    Son tr li choclient (vi achIP client vs hiu cng),gi thng quaserverSocket

    Example: Java client (UDP)

    keyboard monitor

  • 8/3/2019 C2 1page Per Sheet

    102/120

    inFromUser

    Process

    inputstream

    Input: receivespacket (recall

    Clientprocess

    2: Application Layer 101

    sendPacke

    t

    to network from network

    receivePacke

    t

    clientSocket

    UDPpacket

    UDPpacket

    UDP

    socket

    Output: sends

    packet (recallthat TCP sentbyte stream)

    a rece vebyte stream)

    client UDP

    socket

    Example: Java client (UDP)

  • 8/3/2019 C2 1page Per Sheet

    103/120

    import java.io.*;import java.net.*;

    class UDPClient {public static void main(String args[]) throws Exception{

    Create

    2: Application Layer 102

    u ere ea er n rom ser =new BufferedReader(new InputStreamReader(System.in));

    DatagramSocket clientSocket = new DatagramSocket();

    InetAddress IPAddress = InetAddress.getByName("hostname");

    byte[] sendData = new byte[1024];byte[] receiveData = new byte[1024];

    String sentence = inFromUser.readLine();

    sendData = sentence.getBytes();

    Createclient socket

    Translatehostname to IP

    address using DNS

    Example: Java client (UDP), cont.

    Create datagram

  • 8/3/2019 C2 1page Per Sheet

    104/120

    DatagramPacket sendPacket =new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

    clientSocket.send(sendPacket);

    DatagramPacket receivePacket =

    Create datagramwith data-to-send,

    length, IP addr, port

    Send datagramto server

    2: Application Layer 103

    , .

    clientSocket.receive(receivePacket);

    String modifiedSentence =new String(receivePacket.getData());

    System.out.println("FROM SERVER:" + modifiedSentence);

    clientSocket.close();}

    }

    Read datagram

    from server

    Example: Java server (UDP)

  • 8/3/2019 C2 1page Per Sheet

    105/120

    import java.io.*;import java.net.*;

    class UDPServer {

    public static void main(String args[]) throws Exception{Create

    datagram socket

    2: Application Layer 104

    =

    byte[] receiveData = new byte[1024];byte[] sendData = new byte[1024];

    while(true){

    DatagramPacket receivePacket =new DatagramPacket(receiveData, receiveData.length);

    serverSocket.receive(receivePacket);

    at port 9876

    Create space forreceived datagram

    Receivedatagram

    Example: Java server (UDP), contString sentence = new String(receivePacket getData());

  • 8/3/2019 C2 1page Per Sheet

    106/120

    String sentence = new String(receivePacket.getData());

    InetAddress IPAddress = receivePacket.getAddress();

    int port = receivePacket.getPort();

    String capitalizedSentence = sentence.toUpperCase();

    Get IP addrport #, of

    sender

    2: Application Layer 105

    sendData = capitalizedSentence.getBytes();

    DatagramPacket sendPacket =new DatagramPacket(sendData, sendData.length, IPAddress,

    port);

    serverSocket.send(sendPacket);

    }}

    }

    Write outdatagram

    to socket

    End of while loop,loop back and wait foranother datagram

    Create datagramto send to client

    UDP observations & questions

    C client v server u dng DatagramSocket

  • 8/3/2019 C2 1page Per Sheet

    107/120

    C client v server u dng DatagramSocket a ch IP bn nhn v s hiu cng c gn

    tng minh vo segment. iu g s xy ra nu thay i c hai clientSocket ,

    server oc e n my oc e

    Liu client c th gi 1 segment n 1 server mkhng bit n a ch IP ca server v/hoc portnumber?

    C th no nhiu client s dng server ny?

    2: Application Layer 106

    Chapter 2: Application layer

  • 8/3/2019 C2 1page Per Sheet

    108/120

    2.1 Principles ofnetwork applications

    2.2 Web and HTTP 2.3 FTP

    2.6 P2P applications 2.7 Socket programming

    with UDP 2.8 Socket programming

    2: Application Layer 107

    . ec ron c a

    SMTP, POP3, IMAP 2.5 DNS

    Socket-programming using TCP

  • 8/3/2019 C2 1page Per Sheet

    109/120

    TCP service: reliable transfer ofbytes from one processto another

    2: Application Layer 108

    process

    TCP withbuffers,

    variables

    socket

    controlled byapplicationdeveloper

    controlled byoperating

    system

    host orserver

    process

    TCP withbuffers,variables

    socket

    controlled by

    applicationdeveloper

    controlled byoperatingsystem

    host orserver

    internet

    Socket programming with TCPClient phi lin lc vi server Khi c client lin lc, server

  • 8/3/2019 C2 1page Per Sheet

    110/120

    Trc tin, tin trnh serverphi ang chy.

    Server phi c socket cto sn, ch n cc lin lct pha client.

    ,TCP to mi mt socket server process lin lc viclient Cho php server trao i

    vi nhiu client

    2: Application Layer 109

    Client lin lc vi server bng

    cch: To client-local TCP socket Ch nh a ch IP, port

    number ca server process Khi client to socket: client

    TCP thit lp kt ni nserver TCP

    source port numbers c

    dng phn bit client(ni r trong Ch. 3)

    TCP provides reliable, in-ordertransfer of bytes (pipe)between client and server

    Quan im ng dng

    Client/server socket interaction: TCP

    Server (running on hostid) Client

  • 8/3/2019 C2 1page Per Sheet

    111/120

    wait for incomin

    create socket,port=x, for

    incoming request:

    welcomeSocket =ServerSocket()

    create socket,

    TCP

    2: Application Layer 110

    connection requestconnectionSocket =

    welcomeSocket.accept()

    connect to hostid, port=xclientSocket =

    Socket()

    closeconnectionSocket

    read reply fromclientSocket

    closeclientSocket

    send request usingclientSocketread request from

    connectionSocket

    write reply toconnectionSocket

    connect on setup

    keyboard monitor

    Stream jargon

    St e m l d k t i

  • 8/3/2019 C2 1page Per Sheet

    112/120

    inFr

    omUser

    Process

    inputstream

    Client

    process

    Stream l dy cc k t ivo hoc ra khi mtprocess

    Mt input stream c linkt vi mt vi ngun nhp

    2: Application Layer 111

    outToServer

    to network from network

    inFromServer

    clientSocket

    inputstream

    outputstream

    TCPsocket

    client TCPsocket

    ,bn phm hoc socket.

    Mt output stream c linkt vi mt u ra, VD mnhnh hoc socket.

    Socket programming with TCP

    VD v /dng client-server:

  • 8/3/2019 C2 1page Per Sheet

    113/120

    VD v /dng client server:1) Client c dng t standard

    input (inFromUser stream),

    gi n server thng quasocket (outToServer stream)

    2: Application Layer112

    3) Server chuyn i k t trong

    dng thnh ch hoa, gi ngcli client.

    4) Client c, in ra dng b sa it socket (inFromServer

    stream)

    Example: Java client (TCP)

    import java.io.*;

  • 8/3/2019 C2 1page Per Sheet

    114/120

    p j ;import java.net.*;class TCPClient {

    public static void main(String argv[]) throws Exception{

    Strin sentence

    2: Application Layer113

    String modifiedSentence;

    BufferedReader inFromUser =new BufferedReader(new InputStreamReader(System.in));

    Socket clientSocket = new Socket("hostname", 6789);

    DataOutputStream outToServer =new DataOutputStream(clientSocket.getOutputStream());

    Createinput stream

    Createclient socket,

    connect to serverCreate

    output streamattached to socket

    Example: Java client (TCP), cont.

  • 8/3/2019 C2 1page Per Sheet

    115/120

    BufferedReader inFromServer =new BufferedReader(new

    InputStreamReader(clientSocket.getInputStream()));

    sentence = inFromUser.readLine();

    Createinput stream

    attached to socket

    2: Application Layer114

    outToServer.writeBytes(sentence + '\n');

    modifiedSentence = inFromServer.readLine();

    System.out.println("FROM SERVER: " + modifiedSentence);

    clientSocket.close();

    }}

    en neto server

    Read linefrom server

    Example: Java server (TCP)import java.io.*;import java.net.*;

  • 8/3/2019 C2 1page Per Sheet

    116/120

    class TCPServer {

    public static void main(String argv[]) throws Exception{

    String clientSentence;Strin ca italizedSentence

    2: Application Layer 115

    ServerSocket welcomeSocket = new ServerSocket(6789);

    while(true) {

    Socket connectionSocket = welcomeSocket.accept();

    BufferedReader inFromClient =new BufferedReader(newInputStreamReader(connectionSocket.getInputStream()));

    welcoming socket

    at port 6789Wait, on welcomingsocket for contact

    by client

    Create inputstream, attached

    to socket

    Example: Java server (TCP), cont

    C t t t

  • 8/3/2019 C2 1page Per Sheet

    117/120

    DataOutputStream outToClient =

    new DataOutputStream(connectionSocket.getOutputStream());

    clientSentence = inFromClient.readLine();Read in linefrom socket

    Create outputstream, attached

    to socket

    2: Application Layer 116

    capitalizedSentence = clientSentence.toUpperCase() + '\n';

    outToClient.writeBytes(capitalizedSentence);}

    }}

    Write out lineto socket

    End of while loop,

    loop back and wait foranother client connection

    TCP observations & questions

    Server c 2 kiu socket:

  • 8/3/2019 C2 1page Per Sheet

    118/120

    ServerSocket v Socket

    Khi client g vo ca serverSocket, server to raconnectionSocket v hon tt TCP conx.

    vo segment tng minh. Liu nhiu clients c th s dng server?.

    2: Application Layer 117

    Chapter 2: Summary

    application architecturesour study of network apps now complete!

    specific protocols:

  • 8/3/2019 C2 1page Per Sheet

    119/120

    application architectures client-server

    P2P hybrid

    specific protocols: HTTP

    FTP SMTP, POP, IMAP

    DNS

    2: Application Layer 118

    requirements: reliability, bandwidth, delay

    Internet transport servicemodel connection-oriented,reliable: TCP unreliable, datagrams: UDP

    P2P: BitTorrent, Skype

    socket programming

    Chapter 2: Summary

    Most importantly: learned aboutprotocols

  • 8/3/2019 C2 1page Per Sheet

    120/120

    typical request/reply

    message exchange: client requests info or

    Important themes:

    control vs. data msgs

    in-band out-of-band

    2: Application Layer 119

    serv ce server responds with

    data, status code message formats:

    headers: fields giving info

    about data data: info being

    communicated

    centralized vs.

    decentralized stateless vs. stateful

    reliable vs. unreliable

    msg transfer complexity at network

    edge