///发送按钮 /// /// /// privatevoidbutton2_Click(objectsender,EventArgse) { try { IPEndPointclient=(IPEndPoint)this.comboBox1.SelectedItem; if(client==null) { MessageBox.Show("没有选中任何在线客户端!"); return; } if(!this.server.clientCheck(client)) { MessageBox.Show("目标客户端不在线!"); return; } server.sendMessage(client,textBox_msg.Text); } catch(ExceptionEx){MessageBox.Show(Ex.Message);} } /// ///下面显示的 /// /// /// privatevoidshow(IPEndPointipEndPoint,stringstr) { label_zt.Text=ipEndPoint.ToString()":"str; label_all.Text="当前在线人数:"this.server.ClientNumber.ToString(); } /// ///当组合框按下的时候 /// /// /// privatevoidcomboBox1_DropDown_1(objectsender,EventArgse) { try { Listlist=this.server.ClientAll; this.comboBox1.DataSource=list; } catch{} } /// ///关闭客户端的按钮 /// /// /// privatevoidbutton3_Click_1(objectsender,EventArgse) { IPEndPointclient=(IPEndPoint)this.comboBox1.SelectedItem; if(client==null) { MessageBox.Show("没有选中任何在线客户端!"); return; } if(!this.server.clientCheck(client)) { MessageBox.Show("目标客户端不在线!"); return; } server.clientClose(client); } #endregion-IMDN开发者社群-imdn.cn">
///发送按钮 /// /// /// privatevoidbutton2_Click(objectsender,EventArgse) { try { IPEndPointclient=(IPEndPoint)this.comboBox1.SelectedItem; if(client==null) { MessageBox.Show("没有选中任何在线客户端!"); return; } if(!this.server.clientCheck(client)) { MessageBox.Show("目标客户端不在线!"); return; } server.sendMessage(client,textBox_msg.Text); } catch(ExceptionEx){MessageBox.Show(Ex.Message);} } /// ///下面显示的 /// /// /// privatevoidshow(IPEndPointipEndPoint,stringstr) { label_zt.Text=ipEndPoint.ToString()":"str; label_all.Text="当前在线人数:"this.server.ClientNumber.ToString(); } /// ///当组合框按下的时候 /// /// /// privatevoidcomboBox1_DropDown_1(objectsender,EventArgse) { try { Listlist=this.server.ClientAll; this.comboBox1.DataSource=list; } catch{} } /// ///关闭客户端的按钮 /// /// /// privatevoidbutton3_Click_1(objectsender,EventArgse) { IPEndPointclient=(IPEndPoint)this.comboBox1.SelectedItem; if(client==null) { MessageBox.Show("没有选中任何在线客户端!"); return; } if(!this.server.clientCheck(client)) { MessageBox.Show("目标客户端不在线!"); return; } server.clientClose(client); } #endregion - IMDN开发者社群-imdn.cn">
首页 »
C# »
C#实现Socket通讯Demo
于 2021-08-22 发布
0 414
c#通过Socket实现图片、文件和文字的通讯。
private void button1_Click(object sender, EventArgs e)
{
try
{
server = TxStart.startServer(int.Parse(textBox_port.Text));
server.AcceptString = new TxDelegate(acceptString);
server.AcceptByte = new TxDelegate(acceptBytes);
server.Connect = new TxDelegate(connect);
server.dateSuccess = new TxDelegate(dateSuccess);
server.Disconnection = new TxDelegate(disconnection);
server.EngineClose = new TxDelegate(engineClose);
server.EngineLost = new TxDelegate(engineLost);
//server.BufferSize=12048;
//server.FileLog = "C:\test.txt";
server.StartEngine();
this.button1.Enabled = false;
this.button2.Enabled = true;
this.button3.Enabled = true;
}
catch (Exception Ex) { MessageBox.Show(Ex.Message); }
}
///
/// 发送按钮
///
///
///
private void button2_Click(object sender, EventArgs e)
{
try
{
IPEndPoint client = (IPEndPoint)this.comboBox1.SelectedItem;
if (client == null)
{
MessageBox.Show("没有选中任何在线客户端!");
return;
}
if (!this.server.clientCheck(client))
{
MessageBox.Show("目标客户端不在线!");
return;
}
server.sendMessage(client, textBox_msg.Text);
}
catch (Exception Ex) { MessageBox.Show(Ex.Message); }
}
///
/// 下面显示的
///
///
///
private void show(IPEndPoint ipEndPoint, string str)
{
label_zt.Text = ipEndPoint.ToString() ":" str;
label_all.Text = "当前在线人数:" this.server.ClientNumber.ToString();
}
///
/// 当组合框按下的时候
///
///
///
private void comboBox1_DropDown_1(object sender, EventArgs e)
{
try
{
List list = this.server.ClientAll;
this.comboBox1.DataSource = list;
}
catch { }
}
///
/// 关闭客户端的按钮
///
///
///
private void button3_Click_1(object sender, EventArgs e)
{
IPEndPoint client = (IPEndPoint)this.comboBox1.SelectedItem;
if (client == null)
{
MessageBox.Show("没有选中任何在线客户端!");
return;
}
if (!this.server.clientCheck(client))
{
MessageBox.Show("目标客户端不在线!");
return;
}
server.clientClose(client);
}
#endregion
下载说明:请别用迅雷下载,失败请重下,重下不扣分!
-
设置任务栏时间--示例源码下载.zip
设置任务栏时间--示例源码下载.zip
- 2019-08-08下载
- 积分:1
-
C# ftp文件上传 例子源码
C# ftp文件上传 例子源码
- 2014-11-12下载
- 积分:1
-
.Net 通用快速开发系统架构源码(含权限管理系统)_数据库
.Net 通用快速开发系统架构源码(含权限管理系统)_数据库 DotNet.CommonV3.7_20120724_Db 注:仅包含数据库
- 2016-02-25下载
- 积分:1
-
WeiXin调试工具
喜欢的朋友,可以直接拿去反编译出源码
- 2015-08-12下载
- 积分:1
-
动画效果浮动窗体实例
private void StopRectTimer_Tick(object sender, EventArgs e) { //如果鼠标在窗体上,则根据停靠位置显示整个窗体 if (this.Bounds.Contains(Cursor.Position)) { switch (this.StopDock) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, 0); break; case AnchorStyles.Bottom: this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height); break; case AnchorStyles.Left: this.Location = new Point(0, this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y); break; } } else //如果鼠标离开窗体,则根据停靠位置隐藏窗体,但须留出部分窗体边缘以便鼠标选中窗体 { switch (this.StopDock) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, (this.Height - 3) * (-1)); break; case AnchorStyles.Bottom: this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - 5); break; case AnchorStyles.Left: this.Location = new Point((-1) * (this.Width - 3), this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y); break; } } }
- 2015-06-10下载
- 积分:1
-
基于winform的串口调试助手
基于winform的串口调试助手
- 2019-12-27下载
- 积分:1
-
教学监控 socket 通讯
【实例简介】
- 2021-08-10 00:30:54下载
- 积分:1
-
C# 通过windows服务发送邮件 实例源码下载
通过注册服务,实现自动发送邮件 使用说明: 打开cmd输入: 系统盘:WindowsMicrosoft.NETFrameworkv2.0.50727输入:InstallUtil.exe 项目地址(如:InstallUtil.exe E:ProjectWServerSendEmailWindowsServiceSendEmilWindowsServiceSendEmilinDebugWindowsServiceSendEmil.exe)会提示安装成功;这时候右击我的电脑-管理-服务和应用程序-服务,在服务里面就可以找到Service1的服务,这个就是我们刚添加进去的.启动服务后就开始运行程序了;如果你想调式,可以在vs里调式-附加到进程卸载打开cmd 输入 sc delete 服务名称(如Service1)(注意:卸载前先停止服务)
- 2015-03-11下载
- 积分:1
-
物联网开发信息网关(DotNetty)
JT808-Server 是基于Netty和Spring Boot框架,实现了JT/T 808部标协议的服务端程序; 在网上看到Azure团队开源的DotNetty框架,一时兴起写了个基于DotNetty的Tcp Server Demo 解析了JT808的部分指令,应答部分暂时未弄完,代码写的比较随意请不要在意。 部分代码参考了java版本的jt808协议解析 https://github.com/hylexus/jt-808-protocol 感慨JAVA强大的同时,还是喜欢C#强大的语法,希望.net core发展越来越好 直接运行程序,端口默认9623(在Main方法里面修改),可以使用网络调试助手联调(ToolNetAssist.exe)
- 2019-11-08下载
- 积分:1
-
winform listview美化 示例代码
winform listview美化 示例代码
- 2015-05-14下载
- 积分:1