![基于UDP的即時通信工具的設(shè)計開發(fā)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/7/7f8f7a6f-e660-4867-a405-100b9d8eaf86/7f8f7a6f-e660-4867-a405-100b9d8eaf861.gif)
![基于UDP的即時通信工具的設(shè)計開發(fā)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/7/7f8f7a6f-e660-4867-a405-100b9d8eaf86/7f8f7a6f-e660-4867-a405-100b9d8eaf862.gif)
![基于UDP的即時通信工具的設(shè)計開發(fā)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/7/7f8f7a6f-e660-4867-a405-100b9d8eaf86/7f8f7a6f-e660-4867-a405-100b9d8eaf863.gif)
![基于UDP的即時通信工具的設(shè)計開發(fā)_第4頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/7/7f8f7a6f-e660-4867-a405-100b9d8eaf86/7f8f7a6f-e660-4867-a405-100b9d8eaf864.gif)
![基于UDP的即時通信工具的設(shè)計開發(fā)_第5頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/7/7f8f7a6f-e660-4867-a405-100b9d8eaf86/7f8f7a6f-e660-4867-a405-100b9d8eaf865.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、裝訂線 網(wǎng)絡(luò)課程設(shè)計 題目:基于 UDP 的即時通信工具的設(shè)計開發(fā) 學(xué)院:計算機學(xué)院班級姓名: 學(xué)號:指導(dǎo)教師:2015年7月8日 基于 UDP 的即時通信工具的設(shè)計開發(fā) 1 項目名稱 基于 UDP 的即時通信工具的設(shè)計開發(fā) (1)任務(wù)一,設(shè)計一個基于 UDP 的點對點通信工具,實現(xiàn)點對點的通信,如下圖所示,用 戶發(fā)送的信息將在對方用戶中顯示,顯示內(nèi)容包括用戶名+發(fā)送時間+發(fā)送內(nèi)容。 (2) 任務(wù)二,設(shè)計實現(xiàn)一個基于 UDP 的群組即時通信工具,如下圖所示,每個用戶發(fā)送的 信息將在其他用戶中顯示,顯示內(nèi)容包括用戶名+發(fā)送時間+發(fā)送內(nèi)容。 二項目目標(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 的群組即時通信工具l 輸入聊天人名字l 發(fā)送消息給服務(wù)器端,并顯示服務(wù)器端回傳的消息l 接受客戶端發(fā)送的消息,轉(zhuǎn)發(fā)消息給客戶端,并顯示客戶端的消息l 使用文件保存聊天信息 三設(shè)計與實現(xiàn)1. 服務(wù)器端創(chuàng)建套接字(socket)將套接字綁定到一個本地的IP地址及端口上,等待接受對端數(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ù)請求 NO YES處理請求 數(shù)據(jù)應(yīng)答Receive ()Send ()Close()結(jié) 束(圖4.1.1總體流程圖)開 始讀取配置信息啟動服務(wù)器創(chuàng)建套接字,用于收發(fā)信息數(shù)據(jù)接收包數(shù)據(jù)接收包發(fā)送消息保存配置信息結(jié) 束(圖4.1.2服務(wù)器模塊流程2:界面設(shè)計 用戶界面: (用戶登錄界面) (用戶聊天界面) 服務(wù)器界面:(服務(wù)器界面) 3:主要的函數(shù)1:udpclients/用戶端 Form.1/用戶登錄界面 窗體設(shè)計代碼: 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; 功能實現(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è)計代碼: 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;功能實現(xiàn)函數(shù): private bool login()/登陸函數(shù) private void send(string temp)/向服務(wù)器發(fā)送數(shù)據(jù)private void btnSend_Click(object sender, EventArgs e/點擊發(fā)送按鈕發(fā)送輸入信息 private void listen()/監(jiān)聽函數(shù) private void Receive()/啟動接收線程 private void Form2
7、_FormClosing_1(object sender, FormClosingEventArgs e) /關(guān)閉對話框詢問是否關(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è)計代碼: 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; 功能實現(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)/對在線用戶進行群發(fā) private void listen()/監(jiān)聽函數(shù)private void Receive()/啟動接收線程 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. 測試結(jié)果 五總結(jié)與
12、展望在UDP聊天器的設(shè)計過程中,學(xué)習(xí)了c#程序。進一步了解了udp的實現(xiàn)功能。加深了對理論知識和c#控件及MFC Socket的理解,掌握了socket(),send()和的使用方使我的網(wǎng)絡(luò)編程能力得到了提高。同時,也發(fā)現(xiàn)了許多不足之處,如發(fā)送信息的長度受到限制,不能滿足用戶更多字?jǐn)?shù)的聊天需求,這個問題,將是我今后調(diào)整和修改設(shè)計的方向。在這次的課程設(shè)計中,我充分體會到團隊合作的重要性。六源代碼Udpclient 用戶端 登陸:Form1Designer:namespace UDPSever partial class Form1 / <summary> / 必需的設(shè)計器變量。 /
13、</summary> private System.ComponentModel.IContainer components = null; / <summary> / 清理所有正在使用的資源。 / </summary> / <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) if (disposing && (components !=
14、 null) components.Dispose(); base.Dispose(disposing); #region Windows 窗體設(shè)計器生成的代碼 / <summary> / 設(shè)計器支持所需的方法 - 不要 / 使用代碼編輯器修改此方法的內(nèi)容。 / </summary> private void InitializeComponent() this.serverInformation = new System.Windows.Forms.ListBox(); this.message = new System.Windows.Forms.ListBox()
15、; this.clientsList = new System.Windows.Forms.ListBox(); this.btnDelete = new System.Windows.Forms.Button(); this.deleteUser = new System.Windows.Forms.TextBox(); this.btnSaveMesssage = new System.Windows.Forms.Button(); this.SuspendLayout(); / / serverInformation / this.serverInformation.Formatting
16、Enabled = true; this.serverInformation.ItemHeight = 15; this.serverInformation.Location = new System.Drawing.Point(212, 51); this.serverInformation.Margin = new System.Windows.Forms.Padding(4); this.serverInformation.Name = "serverInformation" this.serverInformation.Size = new System.Drawi
17、ng.Size(341, 124); this.serverInformation.TabIndex = 0; this.serverInformation.SelectedIndexChanged += new System.EventHandler(this.serverInformation_SelectedIndexChanged); / / message / this.message.FormattingEnabled = true; this.message.ItemHeight = 15; this.message.Location = new System.Drawing.P
18、oint(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.TabIndex = 1; this.message.SelectedIndexChanged += new System.EventHandler(this.message_SelectedIndexChanged); / / cl
19、ientsList / this.clientsList.FormattingEnabled = true; this.clientsList.ItemHeight = 15; this.clientsList.Location = new System.Drawing.Point(1, 2); this.clientsList.Margin = new System.Windows.Forms.Padding(4); this.clientsList.Name = "clientsList" this.clientsList.Size = new System.Drawi
20、ng.Size(201, 454); this.clientsList.TabIndex = 2; this.clientsList.SelectedIndexChanged += new System.EventHandler(this.clientsList_SelectedIndexChanged); / / btnDelete / this.btnDelete.BackColor = System.Drawing.Color.FromArgb(int)(byte)(192), (int)(byte)(255), (int)(byte)(192); this.btnDelete.Fore
21、Color = 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 = "btnDelete" this.btnDelete.Size = new System.Drawing.Size(100, 29); this.btnDelete.TabIndex =
22、 3; this.btnDelete.Text = "刪除用戶" this.btnDelete.UseVisualStyleBackColor = false this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click); / / deleteUser / this.deleteUser.Location = new System.Drawing.Point(212, 18); this.deleteUser.Margin = new System.Windows.Forms.Padding(4)
23、; 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); / / btnSaveMesssage / this.btnSaveMesssage.BackColor = System.Drawing.Color.FromAr
24、gb(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 = new System.Windows.Forms.Padding(4); this.btnSaveMesssage.Name = &qu
25、ot;btnSaveMesssage" this.btnSaveMesssage.Size = new System.Drawing.Size(148, 29); this.btnSaveMesssage.TabIndex = 5; this.btnSaveMesssage.Text = "保存消息記錄" this.btnSaveMesssage.UseVisualStyleBackColor = false; this.btnSaveMesssage.Click += new System.EventHandler(this.btnSaveMesssage_Cl
26、ick); / / 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(581, 468); this.Controls.Add(this.btnSaveMesssag
27、e); 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 = "Form1" this.Text = "服務(wù)器" thi
28、s.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 System.Windows.Forms.ListBox me
29、ssage; 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.ComponentModel;using System
30、.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 = UserName.Text.ToString(); us
31、er.userKey = PassWord.Text.ToString(); this.DialogResult = DialogResult.OK; /表示點擊按鈕關(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) Program.cs using System;usi
32、ng System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace udpClients static class Program / <summary> / 應(yīng)用程序的主入口點。 / </summary> STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(
33、new Form2(); 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;/本地接收端口號 聊天:Form2.De
34、signer:namespace udpClients partial class Form2 / <summary> / Required designer variable. / </summary> private System.ComponentModel.IContainer components = null;/ <summary> / Clean up any resources being used. / </summary> / <param name="disposing">true if ma
35、naged resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) if (disposing && (components != null) components.Dispose(); base.Dispose(disposing); #region Windows Form Designer generated code / <summary> / Required method for Design
36、er support - do not modify / the contents of this method with the code editor. / </summary> private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2); this.btnSend = new System.Windows.Forms.Bu
37、tton(); this.nowUser = new System.Windows.Forms.ListBox(); this.SendMessage = new System.Windows.Forms.RichTextBox(); this.message = new System.Windows.Forms.ListBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); / btnSend / t
38、his.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.Size = new System.Drawing.Size(127, 56); this.btnSend.TabIndex = 0; this.btnSend.Text = "發(fā)送" this.btnSend.UseV
39、isualStyleBackColor = true; this.btnSend.Click += new System.EventHandler(this.btnSend_Click); / / nowUser / this.nowUser.FormattingEnabled = true; this.nowUser.ItemHeight = 15; this.nowUser.Location = new System.Drawing.Point(29, 29); this.nowUser.Margin = new System.Windows.Forms.Padding(4, 4, 4,
40、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, 305); this.SendMessage.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.SendMessage.Nam
41、e = "SendMessage" this.SendMessage.Size = new System.Drawing.Size(364, 42); this.SendMessage.TabIndex = 2; this.SendMessage.Text = "" this.SendMessage.TextChanged += new System.EventHandler(this.SendMessage_TextChanged); / / message / this.message.BackColor = System.Drawing.Color
42、.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.message.Location = new System.Drawing.Point(177, 31); this.message.Mar
43、gin = 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.message_SelectedIndexChanged); / / label1 / this.label1.Auto
44、Size = 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.label1.Size = new System.Drawing.Size(67, 15)
45、; 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
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 北京課改版歷史八年級下冊第2課《新中國的初步鞏固》聽課評課記錄
- 人民版道德與法治九年級上冊4.2《城鄉(xiāng)差距》聽課評課記錄
- 招投文件合同范本(2篇)
- 生物燃料鍋爐購買合同(2篇)
- 人教版數(shù)學(xué)七年級下冊《7-2-2用坐標(biāo)表示平移》聽評課記錄
- 魯人版道德與法治九年級上冊9.1《公正律師法律援助》配套聽課評課記錄
- 湘師大版道德與法治七年級上冊2.3《快樂學(xué)習(xí)》聽課評課記錄
- 道德與法治部編版七年級上冊同步聽課評課記錄《第8課 生命可以永恒嗎》
- 【部編版】八年級歷史上冊《鴉片戰(zhàn)爭》公開課 聽課評課記錄及教學(xué)反思
- 蘇科版數(shù)學(xué)八年級上冊《課題學(xué)習(xí) 關(guān)于勾股定理的研究》聽評課記錄
- 三廢環(huán)保管理培訓(xùn)
- 財務(wù)管控的間接成本
- 藏族唐卡藝術(shù)特色分析
- 操作系統(tǒng)課程設(shè)計報告
- 護士團隊的協(xié)作和領(lǐng)導(dǎo)力培養(yǎng)培訓(xùn)課件
- QFD模板含計算公式計分標(biāo)準(zhǔn)說明模板
- 醫(yī)院護理培訓(xùn)課件:《早產(chǎn)兒姿勢管理與擺位》
- 人工智能在生物醫(yī)學(xué)倫理與法律中的基因編輯與生命倫理問題研究
- 《論文的寫作技巧》課件
- 國有資產(chǎn)管理辦法-國有資產(chǎn)管理辦法條例
- 公務(wù)車輛定點維修車輛保養(yǎng)(附彩圖) 投標(biāo)方案
評論
0/150
提交評論