在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);