Tran Anh Tuan_06T3_102103061149

  • View
    219

  • Download
    0

Embed Size (px)

Text of Tran Anh Tuan_06T3_102103061149

  • 8/6/2019 Tran Anh Tuan_06T3_102103061149

    1/34

    TRNG I HC BCH KHOA

    KHOA CNG NGH THNG TIN

    B MN MNG V TRUYN THNG

    BO COTHC HNH LP TRNH MNG

    SV thc hin : Trn Anh TunLp : 06T3Nhm : 08AGV hng dn : Nguyn Vn Nguyn

    Nng 2011

    MC LC

  • 8/6/2019 Tran Anh Tuan_06T3_102103061149

    2/34

    Thc hnh lp trnh mng GVHD: Nguyn Vn Nguyn

    CHNG 1. C S L THUYT ........................................................................41.1. MHNHCLIENT-SERVER: ..................................................................................51.2. GIAOTHC TCP ..............................................................................................61.3. GIAOTHC UDP: ............................................................................................6

    CHNG 2. THIT K V XY DNG CHNG TRNH ...........................72.1. LAB1 ............................................................................................................7

    2.1.1. Net1 .....................................................................................................72.1.2. Student Manager .................................................................................92.1.3. NumberTCPSimple ...........................................................................12

    2.2. LAB2 ..........................................................................................................172.2.1. Net1 ...................................................................................................172.2.2. Net2 ...................................................................................................182.2.3. Net3 ...................................................................................................202.2.4. Net4 ...................................................................................................21

    2.2.5. KnockKnock .....................................................................................222.3. LAB3 ..........................................................................................................272.3.1. MulticastPeer ....................................................................................272.3.2. Multicast ............................................................................................29

    CHNG 3. KT LUN V HNG PHT TRIN .....................................34

    Chng 1. C S L THUYT

    SVTH: Trn Anh Tun _06T3 _Nhm 8A 4

  • 8/6/2019 Tran Anh Tuan_06T3_102103061149

    3/34

    Thc hnh lp trnh mng GVHD: Nguyn Vn Nguyn

    1.1. M hnh client-server:M hnh client/server nh sau: Client/Server l m hnh tng qut nht, trn thc t

    th mt server c th c ni ti nhiu server khc nhm lm vic hiu qu v nhanhhn. Khi nhn c 1 yu cu t client, server ny c th gi tip yu cu va nhn

    c cho server khc v d nh database server v bn thn n khng th x l yu cuny c. My server c th thi hnh cc nhim v n gin hoc phc tp. V d nhmt my ch tr li thi gian hin ti trong ngy, khi mt my client yu cu ly thngtin v thi gian n s phi gi mt yu cu theo mt tiu chun do server nh ra, nuyu cu c chp nhn th my server s tr v thng tin m client yu cu. C rtnhiu cc dch v server trn mng nhng n u hot ng theo nguyn l l nhn ccyu cu t client sau x l v tr kt qu cho client yu cu. Thng thng chngtrnh server v client c thi hnh trn hai my khc nhau. Cho d lc no server cng trng thi sn sng ch nhn yu cu t client nhng trn thc t mt tin trnh lintc qua li (interaction) gia client v server li bt u pha client, khi m client gi

    tn hiu yu cu ti server. Cc chng trnh server thng u thi hnh mc ngdng (tng ng dng ca mng). S thun li ca phng php ny l n c th lmvic trn bt c mt mng my tnh no c h tr giao thc truyn thng chun c th y l giao thc TCP/IP. Vi cc giao thc chun ny cng gip cho cc nh sn xutc th tch hp nhiu sn phm khc nhau ca h ln mng m khng gp phi khkhn g. Vi cc chun ny th cc chng trnh server cho mt dch v no y c ththi hnh trn mt h thng chia s thi gian (timesharing system) vi nhiu chngtrnh v dch v khc hoc n c th chy trn chnh mt my tnh cc nhn bnhthng. C th c nhiu chng server cng lm mt dch v, chng c th nm trnnhiu my tnh hoc mt my tnh. Vi m hnh trn chng ta nhn thy rng m hnh

    client/server ch mang c im ca phn mm khng lin quan g n phn cng mcd trn thc t yu cu cho mt my server l cao hn nhiu so vi my client. L do l

    bi v my server phi qun l rt nhiu cc yu cu t cc clients khc nhau trn mng.u v nhc im chnh C th ni rng vi m hnh client/server th mi th dngnh u nm trn bn ca ngi s dng, n c th truy cp d liu t xa (bao gm cccng vic nh gi v nhn file, tm kim thng tin, ...) vi nhiu dch v a dng m mhnh c khng th lm c. M hnh client/server cung cp mt nn tng l tng cho

    php tch hp cc k thut hin i nh m hnh thit k hng i tng, h chuyngia, h thng tin a l (GIS) ... Mt trong nhng vn ny sinh trong m hnh ny l tnh an ton v bo mt thng tin trn mng. Do phi trao i d liu gia 2 my 2khu vc khc nhau cho nn d dng xy ra hin tng thng tin truyn trn mng b l.

    SVTH: Trn Anh Tun _06T3 _Nhm 8A 5

  • 8/6/2019 Tran Anh Tuan_06T3_102103061149

    4/34

    Thc hnh lp trnh mng GVHD: Nguyn Vn Nguyn

    1.2. Giao thc TCP

    - B giao thc TCP/IP, ngn gn l TCP/IP (ting Anh: Internet protocol

    suite hoc IP suite hoc TCP/IP protocol suite - b giao thc lin mng), l mt b

    cc giao thc truyn thng ci t chng giao thc m Internet v hu ht cc mngmy tnh thng mi ang chy trn . B giao thc ny c t tn theo hai giao

    thc chnh ca n l TCP (Giao thc iu khin Giao vn) v IP (Giao thc Lin

    mng). Chng cng l hai giao thc u tin c nh ngha.

    - Nh nhiu b giao thc khc, b giao thc TCP/IP c th c coi l mt

    tp hp cc tng, mi tng gii quyt mt tp cc vn c lin quan n vic truyn

    d liu, v cung cp cho cc giao thc tng cp trn mt dch v c nh ngha r

    rng da trn vic s dng cc dch v ca cc tng thp hn. V mt lgic, cc tng

    trn gn vi ngi dng hn v lm vic vi d liu tru tng hn, chng da vocc giao thc tng cp di bin i d liu thnh cc dng m cui cng c th

    c truyn i mt cch vt l.

    - M hnh OSI miu t mt tp c nh gm 7 tng m mt s nh sn xut la

    chn v n c th c so snh tng i vi b giao thc TCP/IP. S so snh ny c

    th gy nhm ln hoc mang li s hiu bit su hn v b giao thc TCP/IP.

    1.3. Giao thc UDP:- UDP (User Datagram Protocol) l mt trong nhng giao thc ct li ca giao

    thc TCP/IP. Dng UDP, chng trnh trn mng my tnh c th gi nhng d liu

    ngn c gi l datagram ti my khc. UDP khng cung cp s tin cy v th t

    truyn nhn m TCP lm; cc gi d liu c th n khng ng th t hoc b mt m

    khng c thng bo. Tuy nhin UDP nhanh v hiu qu hn i vi cc mc tiu nh

    kch thc nh v yu cu kht khe v thi gian. Do bn cht khng trng thi ca n

    nn n hu dng i vi vic tr li cc truy vn nh vi s lng ln ngi yu cu.

    - Nhng ng dng ph bin s dng UDP nh DNS (Domain Name System), ng

    dng streaming media,Voice over IP, Trivial File Transfer Protocol (TFTP), v game

    trc tuyn.

    SVTH: Trn Anh Tun _06T3 _Nhm 8A 6

    http://vi.wikipedia.org/wiki/Ti%E1%BA%BFng_Anhhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_truy%E1%BB%81n_th%C3%B4nghttp://vi.wikipedia.org/wiki/Ch%E1%BB%93ng_giao_th%E1%BB%A9chttp://vi.wikipedia.org/wiki/Internethttp://vi.wikipedia.org/wiki/TCPhttp://vi.wikipedia.org/wiki/IPhttp://vi.wikipedia.org/w/index.php?title=Giao_th%E1%BB%A9c_t%E1%BA%A7ng_c%E1%BA%A5p_tr%C3%AAn&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Giao_th%E1%BB%A9c_t%E1%BA%A7ng_c%E1%BA%A5p_d%C6%B0%E1%BB%9Bi&action=edit&redlink=1http://vi.wikipedia.org/wiki/M%C3%B4_h%C3%ACnh_OSIhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_TCP/IPhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_TCP/IPhttp://vi.wikipedia.org/wiki/M%E1%BA%A1ng_m%C3%A1y_t%C3%ADnhhttp://vi.wikipedia.org/w/index.php?title=Datagram&action=edit&redlink=1http://vi.wikipedia.org/wiki/TCPhttp://vi.wikipedia.org/wiki/DNShttp://vi.wikipedia.org/w/index.php?title=Streaming_media&action=edit&redlink=1http://vi.wikipedia.org/wiki/Voice_over_IPhttp://vi.wikipedia.org/w/index.php?title=Trivial_File_Transfer_Protocol&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Game_tr%E1%BB%B1c_tuy%E1%BA%BFn&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Game_tr%E1%BB%B1c_tuy%E1%BA%BFn&action=edit&redlink=1http://vi.wikipedia.org/wiki/Ti%E1%BA%BFng_Anhhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_truy%E1%BB%81n_th%C3%B4nghttp://vi.wikipedia.org/wiki/Ch%E1%BB%93ng_giao_th%E1%BB%A9chttp://vi.wikipedia.org/wiki/Internethttp://vi.wikipedia.org/wiki/TCPhttp://vi.wikipedia.org/wiki/IPhttp://vi.wikipedia.org/w/index.php?title=Giao_th%E1%BB%A9c_t%E1%BA%A7ng_c%E1%BA%A5p_tr%C3%AAn&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Giao_th%E1%BB%A9c_t%E1%BA%A7ng_c%E1%BA%A5p_d%C6%B0%E1%BB%9Bi&action=edit&redlink=1http://vi.wikipedia.org/wiki/M%C3%B4_h%C3%ACnh_OSIhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_TCP/IPhttp://vi.wikipedia.org/wiki/Giao_th%E1%BB%A9c_TCP/IPhttp://vi.wikipedia.org/wiki/M%E1%BA%A1ng_m%C3%A1y_t%C3%ADnhhttp://vi.wikipedia.org/w/index.php?title=Datagram&action=edit&redlink=1http://vi.wikipedia.org/wiki/TCPhttp://vi.wikipedia.org/wiki/DNShttp://vi.wikipedia.org/w/index.php?title=Streaming_media&action=edit&redlink=1http://vi.wikipedia.org/wiki/Voice_over_IPhttp://vi.wikipedia.org/w/index.php?title=Trivial_File_Transfer_Protocol&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Game_tr%E1%BB%B1c_tuy%E1%BA%BFn&action=edit&redlink=1http://vi.wikipedia.org/w/index.php?title=Game_tr%E1%BB%B1c_tuy%E1%BA%BFn&action=edit&redlink=1
  • 8/6/2019 Tran Anh Tuan_06T3_102103061149

    5/34

    Thc hnh lp trnh mng GVHD: Nguyn Vn Nguyn

    Chng 2. THIT K V XY DNG CHNGTRNH

    2.1. LAB1

    2.1.1. Net1

    bi: Vit chng trnh x l chui nhp, dng n khi to i tng URL vtr v thuc tnh ca n

    Chc nng chng trnh:

    - Truy cp vo URL, sau in cc thng tin ca ti nguyn nh: