在UDP通信过程中,如果客户端中途断开,服务器会收到一个SocketException
这是非常恐怖的一件事;因为UDP是无连接的;
原因不明~
这里粗暴的给出解决方案
系统环境:win10
开发语言:C#
解决代码:
EndPoint point = new IPEndPoint(IPAddress.Any, 0);
byte[] buffer = new byte[1024];
int SIO_UDP_CONNRESET = -1744830452;
ServerSocket.IOControl((IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0, 0, 0, 0 }, null);
int length = ServerSocket.ReceiveFrom(buffer, ref point);

本文介绍了在Windows 10环境下,使用C#处理UDP通信中客户端突然断开导致的SocketException问题,提供了解决方案,包括设置ServerSocket的IOControl以实现UDP_CONNRESET。
2万+

被折叠的 条评论
为什么被折叠?



