So i have made a game using C# synchronous sockets and have noticed it is really causing a huge drop in my frame rate. I am using UDP with non-blocking. I don't understand why its effecting my frame rate so much?
I know asynchronous is the preferred method with c# but I don't quite understand how that can work in a game environment. Asynchronous makes sense to me in a event driven application as i have seen many examples of this done, just never for games.
this is a sample of my code. Any input on this would be appreciated.
public override Packet UDPReceive()
{
byte[] data = new byte[1024];
try
{
int result = UDPSocket.ReceiveFrom(data, ref epSender);
Packet receivedPacket = new Packet(data);
return receivedPacket;
}
catch (Exception ex)
{
return null;
}
}
Many thanks