2022年点对点通信聊天程序 .pdf
《2022年点对点通信聊天程序 .pdf》由会员分享,可在线阅读,更多相关《2022年点对点通信聊天程序 .pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、点对点通信聊天程序设计文档:基于 SOCKET 的点对点通信聊天Socket是套接字的意思。在套接字下编程很像打电话的过程,打电话之前先申请一条电话线,假设已接至办公室墙上,则相当于申请一个与其他应用程序通信的输入输出接口,而改程序到底与哪个程序通信,取决于其IP 地址。此时,IP 就相当于我们要拨打的电话号码,如果对方也申请了一个Socket ,我们就可以根据其IP 地址跟对方聊天。1.服务器方服务器等待用户从主窗口发来的启动接收消息过程如下:首先建立自己的套接口。然后建立连接调用 listen()函数,开始倾听,再通过accept ()等待接收连接。Accept ()等待请求队列中的请求,
2、一旦有连接请求来到,就可以建立一个与s 有相同属性的套接口。最后关闭套接口。2.客户方客户等待用户从主窗口发来的发送命令,一旦接收到发送请求,调用函数初始化socket ,窗口函数在收到UNSOCK 消息后,判断是由哪个事件引起的,第一次必然是由连接事件引起的,这样就会执行相同的程序。3.程序流程在寻求连接的过程中可能会出现阻塞,是由于操作系统本身原因或者通信信道被其他程序长名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 14 页 - - - - - - - - - 时间
3、占用等导致函数无法返回。这是被阻塞函数会不断调用系统函数来保持消息循环的正常运行。Group 函数group 函数是对数据集按照某个字段或者表达式进行分组,获得一组组的集合,然后从每组中取出一个指定字段或者表达式的值,放到单元格中进行扩展,扩展出来的每个单元格都保留了一个指针指向当前的组集,该组集称为当前组。因此在附属单元格中,需要对该组集进行操作时,不需要用任何条件和主单元格关联,如果加设了条件,反倒导致报表引擎还对组集中的记录进行遍历检索。概要设计:完成的程序应实现如下功能:1 服务器端服务2 客户机服务3 点对点的聊天服务。完成后可看到如下客户页面名师资料总结 - - -精品资料欢迎下载
4、 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 14 页 - - - - - - - - - 只需在对话框里输入信息就可以实现点对点聊天了。附程序源代码:using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets;
5、 using System.IO; using System.Threading; using System.Text; namespace 点对点聊天 / / Form1 的摘要说明。 / public class Form1 : System.Windows.Forms.Form private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private System.Windows
6、.Forms.Label label2; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox textBox4; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label4; private
7、 System.Windows.Forms.Button button3; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.StatusBar statusBar1; private System.Windows.Forms.GroupBox groupBox4; private S
8、ystem.Windows.Forms.Label label5; private System.Windows.Forms.TextBox textBox5; private System.Windows.Forms.TextBox textBox6; private System.Windows.Forms.Label label6; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 14 页 - - - - - - - - - private System.Windo
9、ws.Forms.Button button4; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RichTextBox richTextBox2; private System.Windows.Forms.Button button5; private Thread listenthread;/表示监听的线程 private string msg; /要发送的消息 private Socket socket1; /Socket类用于接收和发送信息 private IPEndPoint
10、lep; private System.Windows.Forms.GroupBox groupBox5; /请求连接的节点 / / 必需的设计器变量。 / private System.ComponentModel.Container components = null; public Form1() / / Windows 窗体设计器支持所必需的 / InitializeComponent(); / / TODO: 在 InitializeComponent 调用后添加任何构造函数代码 / / / 清理所有正在使用的资源。 / protected override void Dispose
11、( bool disposing ) if( disposing ) if (components != null) components.Dispose(); base.Dispose( disposing ); #region Windows 窗体设计器生成的代码 / / private void InitializeComponent() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 14 页 - - - - - - - - - / textBox1 / this
12、.textBox1.Location = new System.Drawing.Point(8, 48); this.textBox1.Name = textBox1; this.textBox1.Size = new System.Drawing.Size(112, 21); this.textBox1.TabIndex = 2; this.textBox1.Text = ; / / label2 / this.label2.Location = new System.Drawing.Point(8, 72); this.label2.Name = label2; this.label2.S
13、ize = new System.Drawing.Size(64, 23); this.label2.TabIndex = 0; this.label2.Text = IP地址 :; this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; / / textBox2 / this.textBox2.Location = new System.Drawing.Point(8, 96); this.textBox2.Name = textBox2; this.textBox2.Size = new System.Draw
14、ing.Size(112, 21); this.textBox2.TabIndex = 2; this.textBox2.Text = ; / / label3 / this.label3.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left); this.label3.Location = new System.Drawing.Point(80, 112); this.label3.Name =
15、 label3; this.label3.Size = new System.Drawing.Size(64, 23); this.label3.TabIndex = 3; this.label3.Text = 我的昵称 :; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; / / textBox3 / this.textBox3.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | S
16、ystem.Windows.Forms.AnchorStyles.Left); this.textBox3.Location = new System.Drawing.Point(136, 112); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 14 页 - - - - - - - - - this.textBox3.Name = textBox3; this.textBox3.Size = new System.Drawing.Size(128, 21); this
17、.textBox3.TabIndex = 4; this.textBox3.Text = ; / / textBox4 / this.textBox4.Location = new System.Drawing.Point(8, 48); this.textBox4.Name = textBox4; this.textBox4.Size = new System.Drawing.Size(120, 21); this.textBox4.TabIndex = 5; this.textBox4.Text = 221.237.165.15; / / button2 / this.button2.An
18、chor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left); this.button2.Location = new System.Drawing.Point(272, 112); this.button2.Name = button2; this.button2.Size = new System.Drawing.Size(72, 23); this.button2.TabIndex = 6; this
19、.button2.Text = 发送 ; this.button2.Click += new System.EventHandler(this.button2_Click); / / label4 / this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label4.Location = new System.Drawing.Point(8, 16); this.label4.Name = label4; this.label4.Size = new System.Drawing.Size(1
20、20, 23); this.label4.TabIndex = 7; this.label4.Text = 服务器 IP:; this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; / / button3 / this.button3.Location = new System.Drawing.Point(8, 48); this.button3.Name = button3; this.button3.Size = new System.Drawing.Size(64, 23); this.button3.Tab
21、Index = 8; this.button3.Text = 开始监听 ; this.button3.Click += new System.EventHandler(this.button3_Click); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 14 页 - - - - - - - - - / / richTextBox1 / this.richTextBox1.Anchor = (System.Windows.Forms.AnchorStyles)(Syst
22、em.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); / textBox6 / this.textBox6.Location = new System.Drawing.Point(80, 80); this.textBox6.Name = textBox6; this.textBox6.Size = new System.D
23、rawing.Size(48, 21); this.textBox6.TabIndex = 5; this.textBox6.Text = ; / / label6 / this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label6.Location = new System.Drawing.Point(8, 80); this.label6.Name = label6; this.label6.Size = new System.Drawing.Size(64, 23); this.lab
24、el6.TabIndex = 7; this.label6.Text = 目标端口 :; this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; / / button5 / this.button5.Location = new System.Drawing.Point(8, 120); this.button5.Name = button5; this.button5.Size = new System.Drawing.Size(64, 23); this.button5.TabIndex = 8; this.b
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年点对点通信聊天程序 2022 点对点 通信 聊天 程序
限制150内