110,538
社区成员
发帖
与我相关
我的任务
分享
while (true)
{
data = new byte[1024];
int length = client.Receive(data);//接收的数据长度
if (length > 0)
{
this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + "客户IP:" + clientip.Address + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + Encoding.UTF8.GetString(data, 0, data.Length-1)));
}
}
while (true)
{
data = new byte[1024];
length = newclient.Receive(data);//接收的数据长度
if (length > 0)
{
this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + "服务器IP:" + clientip.Address + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + Encoding.UTF8.GetString(data, 0, data.Length - 1)));
}
}
data = Encoding.UTF8.GetBytes(this.txtMsg.Text.Trim());
client.Send(data, data.Length, SocketFlags.None);//发送信息
data = Encoding.UTF8.GetBytes(this.txtMsg.Text.Trim());
newclient.Send(data, data.Length, SocketFlags.None);//发送信息