c# UDPClient.Receive 随机收不到数据包
c# UDPClient.Receive randomly not receiving packets
我有一个 .net Framework 4.8 程序,它在后台工作人员不断读取 arduino 在 windows 托管 wifi 网络上发送的 udp 数据包。
从1809更新到windows10 1909后,程序随机停止运行
我安装了 wireshark 来检查我是否收到任何数据,从 arduino IP 到端口 10001 的 UPD 数据包源源不断,但程序卡在 udpclient.receive 没有任何异常抛出.
这是后台工作者的代码:
UdpClient udpClient = new UdpClient(10001);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("192.168.137.4"), 10001);
byte[] receiveBytes;
ardunoPacketTimer.Start();
try
{
while (worker.CancellationPending == false)
{
receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
//When whatever is going wrong happens, the program doesn't get past here
SendArduinoData2Joystick(receiveBytes);
}
}
尝试添加带有一些日志记录的 catch 语句,这样您就不会丢弃可能正在发生的异常。
Windows 是防火墙,禁用它解决了问题。
这很奇怪,因为它并不总是阻止流量,但由于我们在托管网络上禁用了 windows 防火墙,所以一切正常。
我有一个 .net Framework 4.8 程序,它在后台工作人员不断读取 arduino 在 windows 托管 wifi 网络上发送的 udp 数据包。 从1809更新到windows10 1909后,程序随机停止运行
我安装了 wireshark 来检查我是否收到任何数据,从 arduino IP 到端口 10001 的 UPD 数据包源源不断,但程序卡在 udpclient.receive 没有任何异常抛出.
这是后台工作者的代码:
UdpClient udpClient = new UdpClient(10001);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("192.168.137.4"), 10001);
byte[] receiveBytes;
ardunoPacketTimer.Start();
try
{
while (worker.CancellationPending == false)
{
receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
//When whatever is going wrong happens, the program doesn't get past here
SendArduinoData2Joystick(receiveBytes);
}
}
尝试添加带有一些日志记录的 catch 语句,这样您就不会丢弃可能正在发生的异常。
Windows 是防火墙,禁用它解决了问题。 这很奇怪,因为它并不总是阻止流量,但由于我们在托管网络上禁用了 windows 防火墙,所以一切正常。