數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)_第1頁(yè)
數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)_第2頁(yè)
數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)_第3頁(yè)
數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)_第4頁(yè)
數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第一部分 數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)(任務(wù))一、課程設(shè)計(jì)的性質(zhì)、冃的和任務(wù)性質(zhì):獨(dú)立設(shè)課目的和任務(wù):1、掌握數(shù)據(jù)通信和計(jì)算機(jī)網(wǎng)絡(luò)的基本原理2、掌握數(shù)據(jù)通信和計(jì)算機(jī)網(wǎng)絡(luò)設(shè)計(jì)、分析和實(shí)現(xiàn)方法3、提高學(xué)生編制網(wǎng)絡(luò)通信程序、網(wǎng)絡(luò)應(yīng)川服務(wù)程序的能力二、課程設(shè)計(jì)的基本內(nèi)容和要求基本內(nèi)容:網(wǎng)絡(luò)數(shù)據(jù)通信的基本方法及實(shí)現(xiàn)?;疽螅焊鶕?jù)選定的項(xiàng)目,課題小組成員認(rèn)真查閱相關(guān)資料,發(fā)揮學(xué)生的主體作用,提出 設(shè)計(jì)方案,老師參與,進(jìn)行討論和分析,最終確定設(shè)計(jì)方案。在此基礎(chǔ)上,合理分工,協(xié)同 完成項(xiàng)冃的設(shè)計(jì)與實(shí)現(xiàn),最后完成課程設(shè)計(jì)的報(bào)告撰寫(xiě)。三、課程設(shè)計(jì)的內(nèi)容學(xué)時(shí)安排序號(hào)實(shí)驗(yàn)項(xiàng)目學(xué)吋分配實(shí)驗(yàn)類型每組人數(shù)內(nèi)容提要1arp

2、協(xié)議數(shù)據(jù)包的捕 獲解析設(shè)計(jì)與實(shí)現(xiàn)1周設(shè)計(jì)性36人通過(guò)木實(shí)驗(yàn),掌握網(wǎng)絡(luò)協(xié) 議數(shù)據(jù)包捕獲和解析編 程的技術(shù)2基于socket的在線數(shù) 據(jù)傳輸設(shè)計(jì)與實(shí)現(xiàn)1周設(shè)計(jì)性36人基于socket套接u,實(shí)現(xiàn) 通信雙方的在線鍵盤(pán)數(shù) 據(jù)傳輸服務(wù)。目的使學(xué)生 掌握網(wǎng)絡(luò)在線數(shù)據(jù)交換 的設(shè)計(jì)方法。3基于socket的文件傳 輸服務(wù)(ftp)設(shè)計(jì)與 實(shí)現(xiàn)1周設(shè)計(jì)性36人基于socket套接u,實(shí)現(xiàn) 文件數(shù)據(jù)傳輸服務(wù)。冃的 使學(xué)生掌握文件傳輸服 務(wù)的設(shè)計(jì)方法。4基于socket的http文 件傳輸服務(wù)設(shè)計(jì)與實(shí) 現(xiàn)1周設(shè)計(jì)性36人基于socket套接口,實(shí)現(xiàn) http文件數(shù)據(jù)傳輸服 務(wù)。冃的使學(xué)生掌握web 網(wǎng)絡(luò)服務(wù)的設(shè)計(jì)方

3、法。5慕于socket的telnet服 務(wù)設(shè)計(jì)與實(shí)現(xiàn)1周設(shè)計(jì)性36人基于socket套接口,實(shí)現(xiàn) telnet服務(wù)。目的使學(xué)生 掌握遠(yuǎn)程登錄網(wǎng)絡(luò)訪問(wèn) 服務(wù)的設(shè)計(jì)方法。注釋:從上述所列的課程設(shè)計(jì)內(nèi)容中,選擇一個(gè)必做。若冇能力或業(yè)余時(shí)間的學(xué)生,可選擇 一個(gè)以上的設(shè)計(jì)內(nèi)容做。四、課程設(shè)計(jì)報(bào)告要求寫(xiě)出課程設(shè)計(jì)h的,設(shè)計(jì)內(nèi)容,實(shí)驗(yàn)環(huán)境,設(shè)計(jì)思想和實(shí)現(xiàn)流程,源程序、運(yùn)行結(jié)果以及分 析。第二部分涉及到的概念1、socket for c:client - server modelsockets arc used for interprocess coinmunication.most of the inter

4、process communication follow a client-servcr model, where client and server are two separate processes in itself.seiver and client exchange messages over the network throughuserspacekernelspacehardwarewhat is a socket? an interface between application and network which is used for communication betw

5、een processes once configured the application can一 pass data to the socket for network transmission一 receive data from the socket (transmitted through the network by some other host) to the kernel, a socket is an endpoiof communication. to an application, a socket is a file descriptor that lets the

6、application read/write froni/to the network. clients and servers coniniunicate with each by reading from and writing to socket descriptors. remember: all unix i/o devices, including networks, are modeled as files.two essential types of sockets sock_stream tcp connection-oriented reliable delivery in

7、-order guaranteed bidirecti onal sock_dgram udp no notion of ''connection" - appindicates dest. for each packet unreliable delivery no order guarantees can send or receive123what is a port? a port number?一 port numbers are used lo identify services on a host一 port numbers can be well-kn

8、own (port 0-1023) dynamic or private (port 1024-65535)一 servcrs/daeinons usually use well-known ports any client can identify the sen er/seivice http = 8(). ftp = 21, telnet = 23,. /clc/servicc defines well-known ports一 clients usually use dynamic ports assigned by the kernel at run timesocket progr

9、amming with tcpclientserverawait conn ection request from next die ntsocket programming with udpclientserverthis is a blocking call and waits till it receives a request from the clientsockets programming models in mfc(1) introduction mfc in eludes two classes for socket programmi ng, i.e. casy ncsoc

10、ket and csocket. csocket is easier to use than the casyncsocket.(2) common methods create()csocket:create( ulnt nsocketport = 0, int nsockettype = sock_stream,lpctstr ipszsocketaddress = null );where nsockettype= sock_streamtcp=sock_dgramudp conn ect()csocket:connect( lpctstr ipszhostaddress, uint n

11、hostport); lis怕n()csocket :liste n();(3) notification functions onaccept( int nerrorcode); onreceive( int nerrorcode);sequenee of operationsserverclient/ construct a socketcsocket sockwlcm;/ construct a socketcsocket sockclient:/ create the socketsoc kw lc m. create(np ort);/ create the socketsockcl

12、ient.creaie( );2/ start listeningsockwlcm.listen();/ seek a connection sockclient.connectcstraddr, nport);/ conslrucl a new, empty socket csocket sockrecv;/ accept connection sockwlcm.accept( sockrecv);sockrecv.send/ sockrecv.receive()sockclient.send/ sockclient. receive()2> socket for java:socke

13、t programming with tcpapplication viewpointtcp provides reliable, in-ordertransfer of bytes ("pipe")between client and server client must contact server server process must first be running server must have created socket (door) that welcomes client's con tact client con tacts server b

14、y: creating client-local tcp socket specifying ip address, port number of server process when client creates socket: client tcp establishes connection to server tcp when contacted by client, server tcp creates new socket for server process to communicate with client allows server to talk with multip

15、le clientsjava.iang.objecti+-java. net. socket public class socket extends objecttcp socket class used for both client and server new socket is created using a socketo constructor 4 constructors + 2 protected connect with creationcon trolled by application developer controlled by operati ng systempr

16、ocess ir也1匸tcp withbuffers,variablesinternettcp with buffers, variablescon trolled by application developercon trolled by operati ng systemhost or serverhost orservertcp: welcoming and conn ection socketsclient processserver processwelcoming socketsocket programming w讓h tcp example dientserver app:

17、client reads line from standard input (infromuser stream), sends to server via socket (outtoserver stream) server reads line from socket server converts line to uppercase, sends back to client in put stream: sequenceof bytes into process output stream: sequenee of bytes out of processclient socketme

18、eosuiomblud client reads, prints modified line from socket (infromserver stream)client/server socket interact!on: tcpclientserver (running on hostid)create socket, port=xf for incoming request: welcomesocket =serversocketocreate socket, connect to hostid, port=x clientsocket =tcpcbnhecfton sefupsock

19、eto send request using clientsocketread reply from clientsocket close! clientsocketwait for incoming connection request connectionsocket = welcomesocket.acceptoread request from connectionsocketiwrite reply to connectionsocket close 丨 connectionsocketexample: java client (tcp)import java.io.*; impor

20、t .*;class tcpciient public static void main(string argv) throws exception string sente nee;string modifiedsentence;create input streamcreate client socket, :onnect to serverbufferedreader infromuser =new bufferedreader(new inputstreamreader(system.in);socket clientsocket = new socketc'hostname1

21、1, 6789);create output stream attached to socketdataoutputstream outtoserver =new dataoutputstream(clientsocket.getoutputstreamo);example: java client (tcp)createbufferedreader infromserver =input stream attached to socketnew bufferedreader(newin putstreamreader(clientsocket.getl nputstream();senten

22、ce = in fromuser.readli ne();aaaasend line to serverouttoserver.writebytes(se ntence + 'n');read line from servermodifiedsente nee = infromserver.readli ne();a 入 aasystem.out.println(”from server: ” +modifiedse nten ce);die ntsocket.close();example: java server (tcp)import java.io.*; import

23、.*;class tcpserver public static void main(strlng argv) throws exceptioncreate welcoming socket at port 6789wait on welcoming socket for contact by die ntstring dientsentence;string capitalizedsentence;serversocket welcomesocket = new serversocket(6789);while(true) socket connectionsocket = welcomes

24、ocket.accept();create in put stream, attached to socketbufferedreader infromclient =new bufferedreader(newin putstreamreader(conn ectio nsocket.getlnputsteam();example: java server (tcp)create output stream, attached to socketdataoutputstream outtoclient = new dataoutputstream(conn ectio nsocket.get

25、outputsteam();read in line from socketdie ntse ntence = infromclie nt.readli ne();aaaacapitalizedse ntence = die ntsente nce.touppercase() +write out line to socket outtoclie nt.writebytes(capitalizedse nten ce); aaaar、end of while loop, loop back and wait for another client connectionreading direct

26、ly from a url java provides a number of functions that make programming much easier:import .*;import java jo.*;open url as streampublic class urlreader public static void main(string args) throws exception url yahoo = new url(n bufferedreader in = new bufferedreader( new inputstreamreader( yahoo.ope

27、nstream();read and display the web pagestring inputline;while (inputline = in.readline() != null)system.out.println(inputli ne); in.close();no need to implement httpwriting to a urlconnection possible to read and write to a url (using http)import java.io.*;import .*;public class urlwrite public stat

28、ic void main(string args) throws exception allow writing to the urlurl url = new url("httpv//cgi-bin/dictionary”); urlconnection connection = url.openconnection(); con nectio n.setdooutput(tnje);this results in a post request, rather than getprintwriter out = new printwrite

29、r(con nection.getoutputsteam();out.pri ntln( ”book=dictionay&va=java&x=0&y=0“); out.close();/狀態(tài)提示/主機(jī)地址/用戶名/密碼/連接按鈕/斷開(kāi)按鈕/顯示文件和目錄的文本域/要下載的文件名輸入框/保存文件的本機(jī)h錄名/下載按鈕/ ftpclient對(duì)象/輸入流對(duì)彖/構(gòu)造函數(shù)/界血初始化并顯示第三部分實(shí)例1、ftp客戶端程序代碼如f:package ftpclient;import java. awt.import java. awt. event*;import javax.swi

30、ng.*;import sun. net. ftp. *;import sun. net.*;import java, io.*;public class ftpclientfnunc extends jframe jpanel contentpane;label labelprompt = new label();label labelhost = new label ();textfield textfieldhost = new textfieldo;label labeluser = new label ();textfield textfielduser = new textfiel

31、d();label labelpassword = new label();textfield textfieldpassword 二 new textfieldo;button buttonlink 二 new button();button buttondisconnect 二 new button();label labelfileshow = new label();textarea textareacontent = new textarea();label labelfile = new label ();textfield textfieldfile 二 new textfiel

32、do;label labeldir 二 new label ();textfield textfielddir = new textfield();button buttondownload = new button();ftpclient myftp = null:telnetlnputstream instream 二 null;public ftpclientframe() try jbtnito;catch(exception e) e. printstacktrace ();/界而初始化并顯示private void jblnit() throws exception content

33、pane = (jpancl) this gctconlcntpemco ; contentpane. setlayout(null);labelprompt. setbounds(new rectangle(25, 6, 180, 22); labelllost. settext ("主機(jī)名:”);labelhost. setbounds(new rectangle (25, 3& 50, 22); textfieldllost. setbounds (new rectangle(7& 38, 280, 22);label user. settext ("

34、用戶名:);labeluser. setbounds (new rectangle (25, 70, 50, 22); lexlfielduser. setbounds(new rec tangle(78, 70, 114, 22); label pas sword. settext c 密碼:");labelpassword. setbounds(new rectangle(205, 70, 37, 22); textfieldpassword.setbounds(new rectangle(244, 70, 114, 22); textfieldpassword<setec

35、hocharc ;buttonlink. setlabel c連接);buttonlink. setbounds(new rectangle(375, 3& 70, 22);buttonlink.addactionlistener(new java, awt event. actionlistener() public void actionperformed(actionevent e) buttonlink_actionpc:rformed (c););buttonlink. setenabled(true);buttondiscorrncct. sctldbcl ("斷

36、開(kāi)“); buttondisconnect. setbounds(new rectangle(375, 70, 70, 22); buttondisconnect addactionlistener(new java awt event actionlistener() public void actionperformed(actionevent e) buttondisconnect_actionperformed(e););buttondisconnect setenabled(false);labelfileshow. settext c r 錄列表");labelf訂esh

37、ow. setbounds(new rectangle(25, 105, 140, 22);textareacontent. setbounds(new rectangle(25, 135, 420, 235); textareacontent. setedi table(false);labelfile. settext c欲下載的文件名:");labelfile. setbounds(new rectangle (25, 380, 100, 22);textfieldf訂e. setbounds(new rectangle(128, 380, 230, 22);labeldir.

38、 settext ("存放文件的路徑:");labeldir. setbounds(new rectangle(25, 412, 100, 22); textfielddir. setbounds(new rectangle(12& 412, 230, 22);buttondown load. setlabel (下載);buttondownload.setbounds(new rectangle(375, 412, 70, 22);buttondownload addactionlistener(new java awt event actionlistcncr(

39、) public void actionperformed(actionevent e) buttondown1oad_actionperformed(e););buttondownload setenablcd(false);contentpane. add(labelprompt, null);contentpane. add(labelhost, null);contentpane. adcktextfieldllost, null);contentpane. add(labeluser, null);contentpane. add(textfielduser, null);conte

40、ntpane. add(labelpassword, null);contentpane. add(textfie1dpassword, null);contentpcine. add (buttonlink, null);contcntpanc. add(buttondisconncct, null);contentpane add(labelfileshow, null);contentpane. add(textareacontent, null);contentpane. adcktextfieldfile, null);contentpane. add(labelfile, null

41、);contentpane add(labeldir, null);contentpane. add(textfielddir, null);contentpane. add(buttondownload, nul1);enableevents(awtevent. window event mask);thissetsize(new dimension(480, 485);this.setresizable(false);this. settitle(,zftp客戶端");this setvisiblc(truc);響應(yīng)“連接”按鈕的點(diǎn)擊消息,連接到服務(wù)器端void buttonli

42、nk_actionperformed(actionevent e) string hostname 二 lexlfieldhost. geltexto;labelprompt. settext (正在連接,請(qǐng)等待“);try myftp 二 new ftpclient (hostname);/ 構(gòu)造一個(gè)對(duì)彖myftp. login (textfielduser. gettext (), textfieldpassword. gettexto) ;/ 以給定用戶名和密碼登錄myftp. binary () ;/表示文件以二進(jìn)制模式傳輸showfilecontentso ;/列出服務(wù)器端當(dāng)前目錄下

43、的目錄和文件名catch(ftploginexception cl) string strprompt ="用戶名密碼錯(cuò)誤"labelprompt. settext(strprompt);catch (ioexception el) string strprompt ="連接主機(jī):"+ hostname + "失敗!";labelprompt. settext(strprompt);catch(securityexception el) string strprompt ="無(wú)權(quán)限與主機(jī):"+ hostname +

44、 "連接!"labelprompt. settext(strprompt);labelprompt. settext (z/連接主機(jī):"+textfieldhost. gettext ()+"成功!");buttondisconnect. setenab led(true);buttondownload. setenabled(truc);buttonlink. setenablcd(false);/響應(yīng)“斷開(kāi)''按鈕的點(diǎn)擊消息,連接到服務(wù)器端void buttondisconnect_actionpefformed(actio

45、nevent e) try myftp. closeservero ;/關(guān)閉與服務(wù)掘端的連接textareacontent. settext("");labelprompt. settext ("與主機(jī)斷開(kāi)連接");catch(ioexception el) system, out. prin tl n(,zerror: " + el);buttonlink. setenabled(true);buttondownload. setenabled(false);buttondiscormect. setenabled(false);/列出服務(wù)器端當(dāng)前目錄下的目錄和文件名public void showfilecontents() int ch;stringb

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論