NetworkTransport.Receive stops working after error

I’m using the LLAPI to build a multiplayer game with a dedicated server.

I’m using this code to receive network events:

void PollNetwork()
    {
        receivedData = NetworkTransport.Receive(out hostID, out connID, out receivedChan, inputBuffer, inputSize, out receivedSize, out netError);
        if (netError == (byte)NetworkError.Ok)
        {
            switch (receivedData)
            {
                case NetworkEventType.BroadcastEvent:
                    //do stuff
                    break;
                case NetworkEventType.ConnectEvent:
                    //do stuff
                    break;
                case NetworkEventType.DataEvent:
                    //do stuff
                    break;
                case NetworkEventType.DisconnectEvent:
                    //do stuff
                    break;
                case NetworkEventType.Nothing:
                    return;
                default:
                    return;
            }
            PollNetwork();
        }
    }

This is working great for normal traffic but as soon as it receives erroneous data (for example, the buffer may be to long) it stops receiving everything. Is there a way to deal with errors and then resume normal operations?

P.S. I have also tried having the recursive call outside of the if statement; this causes an infinite loop on error, but works otherwise.

Hey @SeanPalmer

When setting up HostTopology, you can create a ConnectionConfig object and set the maximum packet size. Doing this may help avoid buffer overrun.

Also, what messages are you sending from the other party? And how is the logic driving it?

For instance, here you are polling for network events and driving it until exhaustion by returning ONLY when nothing was returned (no input left therefore message exhaustion). Is the sending done in a similar way? Is it very aggressive? Something to look into.

I’ve had no such troubles just by checking for network events once per update loop. They happen often enough.