资源简介
Socket通信,通过异步,解决粘包问题
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TcpIpSocketServer;
namespace SocketClient
{
public partial class Client : Form
{
public Client()
{
InitializeComponent();
}
TcpClient tcpClient = null;
private void btnStart_Click(object sender EventArgs e)
{
tcpClient = new TcpClient(“E:\\“);
tcpClient.ConnectedServer += new NetEvent(tcpClient_ConnectedServer);
tcpClient.DisConnectedServer += new NetEvent(tcpClient_DisConnectedServer);
tcpClient.ReceivedDatagram += new NetEvent(tcpClient_ReceivedDatagram);
tcpClient.Connect(txtIp.Text.Trim().ToString() int.Parse(txtPort.Text.Trim()));
}
///
/// 接受事件
///
///
///
void tcpClient_ReceivedDatagram(object sender NetEventArgs e)
{
}
///
/// 服务器断开事件
///
///
///
void tcpClient_DisConnectedServer(object sender NetEventArgs e)
{
MessageBox.Show(e.Client.ToString());
}
///
/// 连接服务器成功事件
///
///
///
void tcpClient_ConnectedServer(object sender NetEventArgs e)
{
txtRecive.Text = “服务器连接成功,可和进行通信 “ + DateTime.Now;
}
private void button3_Click(object sender EventArgs e)
{
if (tcpClient != null && tcpClient.IsConnected)
{
tcpClient.Close();
}
}
private void btnSend_Click(object sender EventArgs e)
{
for (int i = 0; i < 100; i++)
{
try
{
byte _class = (byte)‘A‘;
tcpClient.SendText(txtSend.Text.Trim() _class);
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
}
private void btnObj_Click(object sender EventArgs e)
{
List lstEntity = new List();
for (int i = 0; i < 100; i++)
{
Entity entity = new Entity();
entity.StrInfo = txtSend.Text.Trim();
lstEntity.Add(entity);
}
try
{
byte _class = 10;
tcpClient.Sendobject(lstEntity _class);
}
catch (Exception ee)
{
MessageBox
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1921 2011-03-22 20:00 MySocket\MySocket.sln
..A..H. 40960 2011-03-26 14:31 MySocket\MySocket.suo
文件 12800 2011-03-26 14:01 MySocket\SocketClient\bin\Debug\SocketClient.exe
文件 30208 2011-03-26 14:01 MySocket\SocketClient\bin\Debug\SocketClient.pdb
文件 26112 2011-03-26 14:01 MySocket\SocketClient\bin\Debug\TcpIpSocketServer.dll
文件 81408 2011-03-26 14:01 MySocket\SocketClient\bin\Debug\TcpIpSocketServer.pdb
文件 35915 2011-03-22 22:11 MySocket\SocketClient\bin\Debug.rar
文件 3974 2011-03-24 09:40 MySocket\SocketClient\Client.cs
文件 9009 2011-03-23 12:48 MySocket\SocketClient\Client.Designer.cs
文件 5814 2011-03-23 12:48 MySocket\SocketClient\Client.resx
文件 350 2011-03-23 19:47 MySocket\SocketClient\Entity.cs
文件 5632 2011-03-24 09:19 MySocket\SocketClient\obj\Debug\Refactor\SocketClient.exe
文件 3189 2011-03-26 14:01 MySocket\SocketClient\obj\Debug\ResolveAssemblyReference.cache
文件 180 2011-03-26 14:01 MySocket\SocketClient\obj\Debug\SocketClient.Client.resources
文件 650 2011-03-22 20:30 MySocket\SocketClient\obj\Debug\SocketClient.csproj.FileListAbsolute.txt
文件 848 2011-03-23 12:48 MySocket\SocketClient\obj\Debug\SocketClient.csproj.GenerateResource.Cache
文件 12800 2011-03-26 14:01 MySocket\SocketClient\obj\Debug\SocketClient.exe
文件 30208 2011-03-26 14:01 MySocket\SocketClient\obj\Debug\SocketClient.pdb
文件 180 2011-03-26 14:01 MySocket\SocketClient\obj\Debug\SocketClient.Properties.Resources.resources
文件 494 2011-03-22 19:34 MySocket\SocketClient\Program.cs
文件 1380 2011-03-22 19:34 MySocket\SocketClient\Properties\AssemblyInfo.cs
文件 2874 2011-03-22 19:34 MySocket\SocketClient\Properties\Resources.Designer.cs
文件 5612 2011-03-22 19:34 MySocket\SocketClient\Properties\Resources.resx
文件 1097 2011-03-22 19:34 MySocket\SocketClient\Properties\Settings.Designer.cs
文件 249 2011-03-22 19:34 MySocket\SocketClient\Properties\Settings.settings
文件 4051 2011-03-22 22:24 MySocket\SocketClient\SocketClient.csproj
文件 12800 2011-03-26 14:01 MySocket\SocketServer\bin\Debug\SocketClient.exe
文件 30208 2011-03-26 14:01 MySocket\SocketServer\bin\Debug\SocketClient.pdb
文件 12800 2011-03-26 14:01 MySocket\SocketServer\bin\Debug\SocketServer.exe
文件 26112 2011-03-26 14:01 MySocket\SocketServer\bin\Debug\SocketServer.pdb
............此处省略66个文件信息
- 上一篇:intel ipp 6.1 破解码 注册
- 下一篇:查询今日宝贝销量小工具
评论
共有 条评论