///发送按钮 /// /// /// 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 125
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
下载说明:请别用迅雷下载,失败请重下,重下不扣分!
-
C# 用树型列表动态显示菜单 例子源码下载
从数据库读取数据 加载至树形空间
- 2015-04-20下载
- 积分:1
-
扫雷游戏
简单的扫雷游戏
- 2020-12-08下载
- 积分:1
-
基于八叉树分解的三维重建
基于八叉树分解的三维重建,原始数据需要有法向量.
- 2019-06-26下载
- 积分:1
-
猜随机数游戏源码(入门级)
猜随机数游戏源码(入门级)
- 2020-03-03下载
- 积分:1
-
XML学习
public Turntable() { InitializeComponent(); int angle = 5029; for (int i = 0; i < 16; i ) { angle = 22; _ListAngle.Add(angle); } } /// /// 保存八个角度 /// List _ListAngle = new List(); /// /// 产生随机数 /// Random _Random = new Random(); int _Index = 0; int _OldAngle = 0; private void btnStartTurntable_Click(object sender, RoutedEventArgs e) { btnStartTurntable.IsEnabled = false; _Index = _Random.Next(0, 16); //_Index = 2; Storyboard sb = (Storyboard)this.FindResource("zhuandong"); sb.Completed -= this.sb_Completed; sb.Completed = new EventHandler(sb_Completed); ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[0]).Value = _OldAngle; ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[3]).Value = _ListAngle[_Index]; //((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[3]).Value = 5218; sb.Begin(); } void sb_Completed(object sender, EventArgs e) { DispatcherTimer dt = new DispatcherTimer(); dt.Interval = TimeSpan.FromSeconds(0.3); dt.Tick = delegate { dt.Stop(); _OldAngle = (_ListAngle[_Index] % 360); btnStartTurntable.IsEnabled = true; AwardProcess(GetAward(_ListAngle[_Index])); }; dt.Start(); } public delegate void AwardDelegate(Award award); /// /// 返回转到的奖项信息 /// public event AwardDelegate AwardProcess; private Award GetAward(int angle) {
- 2014-08-01下载
- 积分:1
-
12306实时火车票查询
12306实时火车票查询
- 2015-05-01下载
- 积分:1
-
C# 柱状图、折线图、饼图源码(chart控件的简单示例)
C# 柱状图、折线图、饼图源码(chart控件的简单示例)
- 2015-06-11下载
- 积分:1
-
C#上位机电表数据采集
C#上位机电表数据采集
- 2021-05-06下载
- 积分:1
-
C#编写的汽车测距防碰撞追尾
【实例简介】OPENCV车道检测与车辆识别
- 2021-05-18 10:33:25下载
- 积分:1
-
RS-232接口 示例源码下载 SerialPortTerminal
RS-232接口 示例源码下载 SerialPortTerminal
- 2021-04-20 23:48:49下载
- 积分:1