嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
超简单的实现服务端和客户端的收发,实现信息接受发送,简单易懂,无复杂代码
/// <summary>
/// 接受客户端信息
/// </summary>
public void ReciveMsg()
{
Socket socketClient = default(Socket);
socketClient = socketServer.Accept(); //返回通信套接字
while (true)
{
Byte[] buffer = new byte[1024];
int len = socketClient.Receive(buffer);
string GetMsg = Encoding.UTF8.GetString(buffer,0, len);
txtReceive.BeginInvoke(new Action(() => {
txtReceive.Text = GetMsg;
}));
socketClient.Send(Encoding.UTF8.GetBytes("收到客户端的信息"));
}
}
/// <summary>
/// 接受客户端信息
/// </summary>
public void ReciveMsg()
{
while (true)
{
Byte[] buffer = new byte[1024];
int len = socket.Receive(buffer);
string GetMsg = Encoding.UTF8.GetString(buffer, 0, len);
textEdit1.BeginInvoke(new Action(() => {
textEdit1.Text = GetMsg;
}));
}
}