c# socket编程。。。 监听端口..???

2020-09-03 社会 109阅读
多线程,
示例:
using System.Threading;
private Socket socket;
//启动线程(可以放在接受按钮事件中);
thread1 = new Thread(new ThreadStart(Revice));
thread2.Start();
//接受信息方法
private string recvStr = "";
private void Revice()
{
while (true)
{
try
{
if (socket.Available != 0)
{
byte[] buffer = new byte[1024];
int length = socket.Receive(buffer);
recvStr =Encoding.Default.GetString(buffer, 0, length);
}
}
}
catch (Exception)
{
}
finally { }
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com