




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、第一部分 數據通信與計算機網絡課程設計(任務)一、課程設計的性質、冃的和任務性質:獨立設課目的和任務:1、掌握數據通信和計算機網絡的基本原理2、掌握數據通信和計算機網絡設計、分析和實現方法3、提高學生編制網絡通信程序、網絡應川服務程序的能力二、課程設計的基本內容和要求基本內容:網絡數據通信的基本方法及實現?;疽螅焊鶕x定的項目,課題小組成員認真查閱相關資料,發(fā)揮學生的主體作用,提出 設計方案,老師參與,進行討論和分析,最終確定設計方案。在此基礎上,合理分工,協同 完成項冃的設計與實現,最后完成課程設計的報告撰寫。三、課程設計的內容學時安排序號實驗項目學吋分配實驗類型每組人數內容提要1arp
2、協議數據包的捕 獲解析設計與實現1周設計性36人通過木實驗,掌握網絡協 議數據包捕獲和解析編 程的技術2基于socket的在線數 據傳輸設計與實現1周設計性36人基于socket套接u,實現 通信雙方的在線鍵盤數 據傳輸服務。目的使學生 掌握網絡在線數據交換 的設計方法。3基于socket的文件傳 輸服務(ftp)設計與 實現1周設計性36人基于socket套接u,實現 文件數據傳輸服務。冃的 使學生掌握文件傳輸服 務的設計方法。4基于socket的http文 件傳輸服務設計與實 現1周設計性36人基于socket套接口,實現 http文件數據傳輸服 務。冃的使學生掌握web 網絡服務的設計方
3、法。5慕于socket的telnet服 務設計與實現1周設計性36人基于socket套接口,實現 telnet服務。目的使學生 掌握遠程登錄網絡訪問 服務的設計方法。注釋:從上述所列的課程設計內容中,選擇一個必做。若冇能力或業(yè)余時間的學生,可選擇 一個以上的設計內容做。四、課程設計報告要求寫出課程設計h的,設計內容,實驗環(huán)境,設計思想和實現流程,源程序、運行結果以及分 析。第二部分涉及到的概念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)提示/主機地址/用戶名/密碼/連接按鈕/斷開按鈕/顯示文件和目錄的文本域/要下載的文件名輸入框/保存文件的本機h錄名/下載按鈕/ ftpclient對象/輸入流對彖/構造函數/界血初始化并顯示第三部分實例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 ("主機名:”);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、開“); 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);響應“連接”按鈕的點擊消息,連接到服務器端void buttonli
42、nk_actionperformed(actionevent e) string hostname 二 lexlfieldhost. geltexto;labelprompt. settext (正在連接,請等待“);try myftp 二 new ftpclient (hostname);/ 構造一個對彖myftp. login (textfielduser. gettext (), textfieldpassword. gettexto) ;/ 以給定用戶名和密碼登錄myftp. binary () ;/表示文件以二進制模式傳輸showfilecontentso ;/列出服務器端當前目錄下
43、的目錄和文件名catch(ftploginexception cl) string strprompt ="用戶名密碼錯誤"labelprompt. settext(strprompt);catch (ioexception el) string strprompt ="連接主機:"+ hostname + "失??!";labelprompt. settext(strprompt);catch(securityexception el) string strprompt ="無權限與主機:"+ hostname +
44、 "連接!"labelprompt. settext(strprompt);labelprompt. settext (z/連接主機:"+textfieldhost. gettext ()+"成功!");buttondisconnect. setenab led(true);buttondownload. setenabled(truc);buttonlink. setenablcd(false);/響應“斷開''按鈕的點擊消息,連接到服務器端void buttondisconnect_actionpefformed(actio
45、nevent e) try myftp. closeservero ;/關閉與服務掘端的連接textareacontent. settext("");labelprompt. settext ("與主機斷開連接");catch(ioexception el) system, out. prin tl n(,zerror: " + el);buttonlink. setenabled(true);buttondownload. setenabled(false);buttondiscormect. setenabled(false);/列出服務器端當前目錄下的目錄和文件名public void showfilecontents() int ch;stringb
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 不同多酚調控豌豆淀粉消化性及其腸道益生特性研究
- 燃煤購銷合同范本
- 直播招商合同范本
- Geogebra在中職三角函數教學中的應用研究
- 黑白幻燈膠片企業(yè)縣域市場拓展與下沉戰(zhàn)略研究報告
- 基因檢測健康管理APP行業(yè)跨境出海戰(zhàn)略研究報告
- 制藥用高壓均質機企業(yè)制定與實施新質生產力戰(zhàn)略研究報告
- 中藥現代化創(chuàng)新藥物行業(yè)深度調研及發(fā)展戰(zhàn)略咨詢報告
- 再生塑料防滑地墊創(chuàng)新行業(yè)跨境出海戰(zhàn)略研究報告
- 安胎仿制藥行業(yè)跨境出海戰(zhàn)略研究報告
- 2022人臉識別安全白皮書
- 無人機應用案例-石油領域油氣管線巡查
- 青島版三年級下冊口算題大全(全冊完整)
- 固定翼飛機的結構和飛行原理
- 內蒙古鄂爾多斯杭錦經濟開發(fā)區(qū)地質災害危險性評估報告
- DB23T 2656-2020樺樹液采集技術規(guī)程
- 2023年蘇州職業(yè)大學單招職業(yè)適應性測試題庫及答案解析
- 中國故事英文版哪吒英文二篇
- 2023年中智集團及下屬單位招聘筆試題庫及答案解析
- GB/T 8888-2003重有色金屬加工產品的包裝、標志、運輸和貯存
- GB/T 21872-2008鑄造自硬呋喃樹脂用磺酸固化劑
評論
0/150
提交評論