c# udp socket 怎样向远程端口请求数据
发布网友
发布时间:2022-04-27 07:06
我来回答
共1个回答
热心网友
时间:2022-06-28 05:59
UdpClient receive = new UdpClient(port);
IPAddress ip;
if (sIP == "0")
ip = IPAddress.Any;
else
ip = IPAddress.Parse(sIP);
IPEndPoint ipport = new IPEndPoint(ip, port);
string content = "";
int i = 0;
while (true)
{
byte[] buffer = receive.Receive(ref ipport);
string message = Encoding.UTF8.GetString(buffer);
if (message.Length > 0)
{
Console.WriteLine(message);
content = content + message + "\n";
if (i >= 50)
{
OutputFile(outputFileName, content);
content = "";
i = 0;
}
}
i++;
Thread.Sleep(100);
}