網(wǎng)絡(luò)課程設(shè)計(jì)基于UDP的即時(shí)通信工具的設(shè)計(jì)開發(fā)_第1頁(yè)
網(wǎng)絡(luò)課程設(shè)計(jì)基于UDP的即時(shí)通信工具的設(shè)計(jì)開發(fā)_第2頁(yè)
網(wǎng)絡(luò)課程設(shè)計(jì)基于UDP的即時(shí)通信工具的設(shè)計(jì)開發(fā)_第3頁(yè)
網(wǎng)絡(luò)課程設(shè)計(jì)基于UDP的即時(shí)通信工具的設(shè)計(jì)開發(fā)_第4頁(yè)
網(wǎng)絡(luò)課程設(shè)計(jì)基于UDP的即時(shí)通信工具的設(shè)計(jì)開發(fā)_第5頁(yè)
已閱讀5頁(yè),還剩38頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、裝訂線 網(wǎng)絡(luò)課程設(shè)計(jì) 題目:基于 udp 的即時(shí)通信工具的設(shè)計(jì)開發(fā) 學(xué)院:計(jì)算機(jī)學(xué)院班級(jí)姓名: 學(xué)號(hào):指導(dǎo)教師:2015年7月8日 基于 udp 的即時(shí)通信工具的設(shè)計(jì)開發(fā) 1 項(xiàng)目名稱 基于 udp 的即時(shí)通信工具的設(shè)計(jì)開發(fā) (1)任務(wù)一,設(shè)計(jì)一個(gè)基于 udp 的點(diǎn)對(duì)點(diǎn)通信工具,實(shí)現(xiàn)點(diǎn)對(duì)點(diǎn)的通信,如下圖所示,用 戶發(fā)送的信息將在對(duì)方用戶中顯示,顯示內(nèi)容包括用戶名+發(fā)送時(shí)間+發(fā)送內(nèi)容。 (2) 任務(wù)二,設(shè)計(jì)實(shí)現(xiàn)一個(gè)基于 udp 的群組即時(shí)通信工具,如下圖所示,每個(gè)用戶發(fā)送的 信息將在其他用戶中顯示,顯示內(nèi)容包括用戶名+發(fā)送時(shí)間+發(fā)送內(nèi)容。 二項(xiàng)目目標(biāo)(1)熟悉 c#.net 開發(fā)環(huán)境 (2)熟悉

2、 socket 等相關(guān)通信組件 (3)通信協(xié)議的定義、封裝與解析 資料查閱:可以通過socket udp c#, 和socket 異步 udp c#等關(guān)鍵詞在網(wǎng)絡(luò)上了解相關(guān)資料。 基于 udp 的群組即時(shí)通信工具l 輸入聊天人名字l 發(fā)送消息給服務(wù)器端,并顯示服務(wù)器端回傳的消息l 接受客戶端發(fā)送的消息,轉(zhuǎn)發(fā)消息給客戶端,并顯示客戶端的消息l 使用文件保存聊天信息 三設(shè)計(jì)與實(shí)現(xiàn)1. 服務(wù)器端創(chuàng)建套接字(socket)將套接字綁定到一個(gè)本地的ip地址及端口上,等待接受對(duì)端數(shù)據(jù)(receive),關(guān)閉套接字。2. 客戶端創(chuàng)建套接字,向服務(wù)器發(fā)送數(shù)據(jù)(send ),關(guān)閉套接字。1、 流程圖開 始 ud

3、pserver服務(wù)器socket() udpclients客戶端socket()bind()receivesend () 數(shù)據(jù)請(qǐng)求 no yes處理請(qǐng)求 數(shù)據(jù)應(yīng)答receive ()send ()close()結(jié) 束(圖4.1.1總體流程圖)開 始讀取配置信息啟動(dòng)服務(wù)器創(chuàng)建套接字,用于收發(fā)信息數(shù)據(jù)接收包數(shù)據(jù)接收包發(fā)送消息保存配置信息結(jié) 束(圖4.1.2服務(wù)器模塊流程2:界面設(shè)計(jì) 用戶界面: (用戶登錄界面) (用戶聊天界面) 服務(wù)器界面:(服務(wù)器界面) 3:主要的函數(shù)1:udpclients/用戶端 form.1/用戶登錄界面 窗體設(shè)計(jì)代碼: private system.windows.fo

4、rms.textbox password; private system.windows.forms.label label1; private system.windows.forms.textbox username; private system.windows.forms.label label2; private system.windows.forms.button btnlogin; 功能實(shí)現(xiàn)函數(shù): private void button2_click(object sender, eventargs e) private void username_textchanged(ob

5、ject sender, eventargs e) private void password_textchanged(object sender, eventargs e) form.2/用戶聊天界面窗體設(shè)計(jì)代碼: private system.windows.forms.button btnsend; private system.windows.forms.listbox nowuser; private system.windows.forms.richtextbox sendmessage; private system.windows.forms.label label1; pri

6、vate system.windows.forms.label label2; private system.windows.forms.listbox message;功能實(shí)現(xiàn)函數(shù): private bool login()/登陸函數(shù) private void send(string temp)/向服務(wù)器發(fā)送數(shù)據(jù)private void btnsend_click(object sender, eventargs e/點(diǎn)擊發(fā)送按鈕發(fā)送輸入信息 private void listen()/監(jiān)聽函數(shù) private void receive()/啟動(dòng)接收線程 private void form2

7、_formclosing_1(object sender, formclosingeventargs e) /關(guān)閉對(duì)話框詢問是否關(guān)閉 private void sendmessage_textchanged(object sender, eventargs e)private void message_selectedindexchanged(object sender, eventargs e) private void form2_load(object sender, eventargs e)private void label2_click(object sender, eventar

8、gs e)2:udpserver/服務(wù)器 from.1/服務(wù)器界面窗體設(shè)計(jì)代碼: private system.windows.forms.listbox serverinformation; private system.windows.forms.listbox message; private system.windows.forms.listbox clientslist; private system.windows.forms.button btndelete; private system.windows.forms.textbox deleteuser; private sys

9、tem.windows.forms.button btnsavemesssage; 功能實(shí)現(xiàn)函數(shù):public form1() private int searchclient(string username)/查詢username用戶是否在列表private bool clientlogin(string receivedata,ipaddress dstip)/登錄函數(shù)處理用戶登錄和添加 private bool clientleave(string username)/用戶下線函數(shù) private void show()/顯示當(dāng)前服務(wù)器信息和在線用戶并更新用戶列表 private voi

10、d send(string senddata,int norec)/對(duì)在線用戶進(jìn)行群發(fā) private void listen()/監(jiān)聽函數(shù)private void receive()/啟動(dòng)接收線程 private void form1_formclosing(object sender, formclosingeventargs e) private void serverinformation_selectedindexchanged(object sender, eventargs e) private void message_selectedindexchanged(object s

11、ender, eventargs e) private void textbox1_textchanged(object sender, eventargs e) private void btnsavemesssage_click(object sender, eventargs e)/保存消息日志 private void btndelete_click(object sender, eventargs e)/刪除指定用戶private void clientslist_selectedindexchanged(object sender, eventargs e)4. 測(cè)試結(jié)果 五總結(jié)與

12、展望在udp聊天器的設(shè)計(jì)過程中,學(xué)習(xí)了c#程序。進(jìn)一步了解了udp的實(shí)現(xiàn)功能。加深了對(duì)理論知識(shí)和c#控件及mfc socket的理解,掌握了socket(),send()和的使用方使我的網(wǎng)絡(luò)編程能力得到了提高。同時(shí),也發(fā)現(xiàn)了許多不足之處,如發(fā)送信息的長(zhǎng)度受到限制,不能滿足用戶更多字?jǐn)?shù)的聊天需求,這個(gè)問題,將是我今后調(diào)整和修改設(shè)計(jì)的方向。在這次的課程設(shè)計(jì)中,我充分體會(huì)到團(tuán)隊(duì)合作的重要性。六源代碼udpclient 用戶端 登陸:form1designer:namespace udpsever partial class form1 / / 必需的設(shè)計(jì)器變量。 / private system.c

13、omponentmodel.icontainer components = null; / / 清理所有正在使用的資源。 / / 如果應(yīng)釋放托管資源,為 true;否則為 false。 protected override void dispose(bool disposing) if (disposing & (components != null) components.dispose(); base.dispose(disposing); #region windows 窗體設(shè)計(jì)器生成的代碼 / / 設(shè)計(jì)器支持所需的方法 - 不要 / 使用代碼編輯器修改此方法的內(nèi)容。 / private

14、 void initializecomponent() this.serverinformation = new system.windows.forms.listbox(); this.message = new system.windows.forms.listbox(); this.clientslist = new system.windows.forms.listbox(); this.btndelete = new system.windows.forms.button(); this.deleteuser = new system.windows.forms.textbox();

15、 this.btnsavemesssage = new system.windows.forms.button(); this.suspendlayout(); / / serverinformation / this.serverinformation.formattingenabled = true; this.serverinformation.itemheight = 15; this.serverinformation.location = new system.drawing.point(212, 51); this.serverinformation.margin = new s

16、ystem.windows.forms.padding(4); this.serverinformation.name = serverinformation; this.serverinformation.size = new system.drawing.size(341, 124); this.serverinformation.tabindex = 0; this.serverinformation.selectedindexchanged += new system.eventhandler(this.serverinformation_selectedindexchanged);

17、/ / message / this.message.formattingenabled = true; this.message.itemheight = 15; this.message.location = new system.drawing.point(212, 228); this.message.margin = new system.windows.forms.padding(4); this.message.name = message this.message.size = new system.drawing.size(341, 229); this.message.ta

18、bindex = 1; this.message.selectedindexchanged += new system.eventhandler(this.message_selectedindexchanged); / / clientslist / this.clientslist.formattingenabled = true; this.clientslist.itemheight = 15; this.clientslist.location = new system.drawing.point(1, 2); this.clientslist.margin = new system

19、.windows.forms.padding(4); this.clientslist.name = clientslist; this.clientslist.size = new system.drawing.size(201, 454); this.clientslist.tabindex = 2; this.clientslist.selectedindexchanged += new system.eventhandler(this.clientslist_selectedindexchanged); / / btndelete / this.btndelete.backcolor

20、= system.drawing.color.fromargb(int)(byte)(192), (int)(byte)(255), (int)(byte)(192); this.btndelete.forecolor = system.drawing.systemcolors.controldarkdark; this.btndelete.location = new system.drawing.point(453, 13); this.btndelete.margin = new system.windows.forms.padding(4); this.btndelete.name =

21、 btndelete; this.btndelete.size = new system.drawing.size(100, 29); this.btndelete.tabindex = 3; this.btndelete.text = 刪除用戶; this.btndelete.usevisualstylebackcolor = false this.btndelete.click += new system.eventhandler(this.btndelete_click); / / deleteuser / this.deleteuser.location = new system.dr

22、awing.point(212, 18); this.deleteuser.margin = new system.windows.forms.padding(4); this.deleteuser.name = deleteuser; this.deleteuser.size = new system.drawing.size(203, 25); this.deleteuser.tabindex = 4; this.deleteuser.textchanged += new system.eventhandler(this.textbox1_textchanged); / / btnsave

23、messsage / this.btnsavemesssage.backcolor = system.drawing.color.fromargb(int)(byte)(255), (int)(byte)(255), (int)(byte)(192); this.btnsavemesssage.forecolor = system.drawing.systemcolors.controldarkdark; this.btnsavemesssage.location = new system.drawing.point(405, 191); this.btnsavemesssage.margin

24、 = new system.windows.forms.padding(4); this.btnsavemesssage.name = btnsavemesssage; this.btnsavemesssage.size = new system.drawing.size(148, 29); this.btnsavemesssage.tabindex = 5; this.btnsavemesssage.text = 保存消息記錄; this.btnsavemesssage.usevisualstylebackcolor = false; this.btnsavemesssage.click +

25、= new system.eventhandler(this.btnsavemesssage_click); / / form1 / this.autoscaledimensions = new system.drawing.sizef(8f, 15f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.backcolor = system.drawing.systemcolors.gradientactivecaption; this.clientsize = new system.drawing.size

26、(581, 468); this.controls.add(this.btnsavemesssage); this.controls.add(this.deleteuser); this.controls.add(this.btndelete); this.controls.add(this.clientslist); this.controls.add(this.message); this.controls.add(this.serverinformation); this.margin = new system.windows.forms.padding(4); this.name =

27、form1; this.text = 服務(wù)器; this.formclosing += new system.windows.forms.formclosingeventhandler(this.form1_formclosing); this.load += new system.eventhandler(this.form1_load); this.resumelayout(false); this.performlayout(); #endregion private system.windows.forms.listbox serverinformation; private syst

28、em.windows.forms.listbox message; private system.windows.forms.listbox clientslist; private system.windows.forms.button btndelete; private system.windows.forms.textbox deleteuser; private system.windows.forms.button btnsavemesssage; from1.csusing system;using system.collections.generic;using system.

29、componentmodel;using system.data;using system.drawing;using system.linq;using system.text;using system.windows.forms;namespace udpclients public partial class form1 : form public form1() initializecomponent();/初始化工作 加載控件資源 分配資源 private void button2_click(object sender, eventargs e) user.username = u

30、sername.text.tostring(); user.userkey = password.text.tostring(); this.dialogresult = dialogresult.ok; /表示點(diǎn)擊按鈕關(guān)閉窗口 private void form1_load(object sender, eventargs e)/分配窗口使用資源 private void username_textchanged(object sender, eventargs e) private void password_textchanged(object sender, eventargs e)

31、program.cs using system;using system.collections.generic;using system.linq;using system.windows.forms;namespace udpclients static class program / / 應(yīng)用程序的主入口點(diǎn)。 / stathread static void main() application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new fo

32、rm2(); user.csusing system;using system.collections.generic;using system.linq;using system.text;using system.net;using system.net.socketsnamespace udpclients class user/本地用戶類 public static string username;/y用戶名 public static string userkey;/用戶密碼 public static int myrecport;/本地接收端口號(hào) 聊天:form2.designer

33、:namespace udpclients partial class form2 / / required designer variable. / private system.componentmodel.icontainer components = null;/ / clean up any resources being used. / / true if managed resources should be disposed; otherwise, false. protected override void dispose(bool disposing) if (dispos

34、ing & (components != null) components.dispose(); base.dispose(disposing); #region windows form designer generated code / / required method for designer support - do not modify / the contents of this method with the code editor. / private void initializecomponent() system.componentmodel.componentreso

35、urcemanager resources = new system.componentmodel.componentresourcemanager(typeof(form2); this.btnsend = new system.windows.forms.button(); this.nowuser = new system.windows.forms.listbox(); this.sendmessage = new system.windows.forms.richtextbox(); this.message = new system.windows.forms.listbox();

36、 this.label1 = new system.windows.forms.label(); this.label2 = new system.windows.forms.label(); this.suspendlayout(); / btnsend / this.btnsend.location = new system.drawing.point(551, 299); this.btnsend.margin = new system.windows.forms.padding(4, 4, 4, 4); this.btnsend.name = btnsend; this.btnsend

37、.size = new system.drawing.size(127, 56); this.btnsend.tabindex = 0; this.btnsend.text = 發(fā)送; this.btnsend.usevisualstylebackcolor = true; this.btnsend.click += new system.eventhandler(this.btnsend_click); / / nowuser / this.nowuser.formattingenabled = true; this.nowuser.itemheight = 15; this.nowuser

38、.location = new system.drawing.point(29, 29); this.nowuser.margin = new system.windows.forms.padding(4, 4, 4, 4); this.nowuser.name = nowuser; this.nowuser.size = new system.drawing.size(119, 259); this.nowuser.tabindex = 1; / / sendmessage / this.sendmessage.location = new system.drawing.point(177,

39、 305); this.sendmessage.margin = new system.windows.forms.padding(4, 4, 4, 4); this.sendmessage.name = sendmessage; this.sendmessage.size = new system.drawing.size(364, 42); this.sendmessage.tabindex = 2; this.sendmessage.text = ; this.sendmessage.textchanged += new system.eventhandler(this.sendmess

40、age_textchanged); / / message / this.message.backcolor = system.drawing.color.white; this.message.font = new system.drawing.font(微軟雅黑, 9f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, (byte)(134); this.message.formattingenabled = true; this.message.itemheight = 20; this.messa

41、ge.location = new system.drawing.point(177, 31); this.message.margin = new system.windows.forms.padding(4, 4, 4, 4); this.message.name = message; this.message.size = new system.drawing.size(499, 244); this.message.tabindex = 3; this.message.selectedindexchanged += new system.eventhandler(this.messag

42、e_selectedindexchanged); / / label1 / this.label1.autosize = true; this.label1.backcolor = system.drawing.systemcolors.gradientactivecaption; this.label1.location = new system.drawing.point(175, 9); this.label1.margin = new system.windows.forms.padding(4, 0, 4, 0); this.label1.name = label1; this.la

43、bel1.size = new system.drawing.size(67, 15); this.label1.tabindex = 5; this.label1.text = 聊天記錄; / / label2 / this.label2.autosize = true; this.label2.backcolor = system.drawing.systemcolors.gradientactivecaption; this.label2.location = new system.drawing.point(29, 9); this.label2.margin = new system.windows.forms.padding(4, 0, 4, 0); this.label2.name = label2; this.label2.size = new system.drawing.size(67, 15); this.label2.tabindex = 6; this.label2.text = 用戶列表; this.label2.click += new system.eventhandler(this.label2_click); / / form

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論