Peer timeout/disconnect when debugging (c# visual studio)

Godot Version

4.4.1

Question

Could not find another question on this topic so posting this here hopefully saving someone else some time:

When debugging either a client or server, the server/client will disconnect when I am viewing a breakpoint in Visual Studio. My guess is that the client or server times out. I have tried to set both client and server timeouts using e.g. on server:

public override void _Ready()
{
    Multiplayer.PeerConnected += Multiplayer_PeerConnected;
}

private void Multiplayer_PeerConnected(long id)
{
    int peerId = (int)id;
    //Default values in enet.h are 32, 5000, 30000, see e.g. ENET_PEER_TIMEOUT_LIMIT in the enum there
    //https://github.com/lsalzman/enet/blob/master/include/enet/enet.h
    if (TimeoutMS > 0)
    {
        ENetPacketPeer newPeer = ((ENetMultiplayerPeer)Multiplayer.MultiplayerPeer).GetPeer(peerId);
        newPeer.SetTimeout(32, TimeoutMS, TimeoutMS);
    }
}

or on client:

private void JoinServer()
{
    var peer = new ENetMultiplayerPeer();
    Multiplayer.ConnectedToServer += Multiplayer_ConnectedToServer;
    Error error = peer.CreateClient(IpInput.Text, PortInput.Text.ToInt());

    Multiplayer.MultiplayerPeer = peer;
}

 private void Multiplayer_ConnectedToServer()
 {
     var serverPeer = ((ENetMultiplayerPeer)Multiplayer.MultiplayerPeer).GetPeer(1);
     //Default values in enet.h are 32, 5000, 30000
     if (TimeoutMS > 0)
         serverPeer.SetTimeout(32, TimeoutMS, TimeoutMS);
 }

This seems to work if both server and peer set high values for the timeout, e.g. 10 minutes.

1 Like

I have noticed this, although i just restart the peers. I wonder if the editor could easily pause all windows on a breakpoint… It basically because the multiplayer api is not being polled.

If you dont have any autoloads you could try setting up two peers in the same tree. That way both peers are paused during a breakpoint since there is only one process.