2

As part of a game I'm developing a server is receiving UDP packets from up to 8 players at around 18 packets per second. All these packets are received by one UDPclient on the server end. I'm wondering if UDP packets can merge the same as TCP packets. If not does the UDPclient just take one packet per frame from a queue, meaning I'll run into problems if the server is receiving more packets per second then the frame-rate?

This is using System.Net.Sockets.

if (ServerUDP != null)
{
    if (ServerUDP.Available != 0)
    {
        IPEndPoint receiveEP = new IPEndPoint(IPAddress.Any, 0);
        byte[] packetReceived = ServerUDP.Receive(ref receiveEP);
    }
}
CSDev
  • 3,177
  • 6
  • 19
  • 37
  • [The docs](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.receive#remarks) state: "When data is available, the Receive method will read the **first** enqueued datagram and return the data portion as a byte array." Does that help at all? – Joelius Aug 02 '19 at 08:38
  • I think that does answer whether they're taken from a queue. I'm guessing since there is a queue active the packets don't need to merge to be received. Not 100% sure though. – Isaac Phillips Aug 02 '19 at 08:57
  • Me neither, that's why I don't want to make this into an answer even though it probably is what you're looking for. – Joelius Aug 02 '19 at 09:02
  • UDP works with individual datagrams, not packets, hence the "D" in UDP, while TCP works with streams of data that are segmented and reassembled. TCP has guarantees and is reliable, while UDP has no guarantees and is unreliable. Basically, TCP knows what to expect next, while UDP is not actually expecting anything. – Ron Maupin Aug 02 '19 at 13:31
  • Since UDP has no built-in flow control, the usual strategy for UDP servers is to have one task (or thread) receive the incoming datagrams as fast as possible and put them into some queue, in order to avoid losing data (if your app does not read the incoming datagrams fast enough the network stack will just drop them). The actual processing of the data is done in other task(s). – C. Gonzalez Aug 02 '19 at 16:03

0 Answers0