Been having an reoccurring issue with my server/client interaction. One in every like 15-20 disconnections (sometimes more, or less, frequent) my server will register a 10054 exception. When this happens, the server seizes up and has to be restarted, which is really annoying to deal with.
The exception always occurs in this code block on the 6th line down (starting "byte[] data ="):
private static void UDPReceiveCallback(IAsyncResult result)
{
try
{
IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] data = udpListener.EndReceive(result, ref clientEndPoint);
udpListener.BeginReceive(UDPReceiveCallback, null);
if(data.Length<4)
{
return;
}
using(Packet packet = new Packet(data))
{
int clientID = packet.ReadInt();
if(clientID == 0)
{
return;
}
if(clients[clientID].udp.endPoint == null)
{
clients[clientID].udp.Connect(clientEndPoint);
return;
}
if(clients[clientID].udp.endPoint.ToString() == clientEndPoint.ToString())
{
clients[clientID].udp.HandleData(packet);
}
}
}
catch(Exception ex)
{
Console.WriteLine($"Error receiving UDP data: {ex}");
}
}
I've tried a few different things to try and fix it, but most times end up making it worse. Frankly I don't understand what this exception means or why it is caused, which makes bugfixing harder. I'd appreciate any insight into the source of this exception as well as maybe how I could fix it.
Thanks!