#How to handle when client connects before server starts listening?

9 messages · Page 1 of 1 (latest)

pearl lantern
#

When testing in dedicated mode, sometimes my client starts connecting before the server has started listening. This results in the client doing nothing. I can't figure out which event to listen to in order to auto reconnect. NetworkClient.OnDisconnectedEvent does not fire in this case.

#

I just tried to listen to Transport.active.OnClientDisconnected and call NetworkManager.StartClient(uri); after one second. This results in client failing with this error upon reconnect:

old ruin
pearl lantern
#

@old ruin in our prod setup this isn't the case. We often will startup servers on demand and client may start connecting before server finishes starting (kubernetes sometimes takes a bit to spin up a pod)

#

In this scenario i'm trying to use unity's new MPPM tooling to auto start a server in a separate window.

#

FWIW i'm migrating from fish-net to Mirror. Mirror has been great so far but this has tripped me up.

nova trout
#

maybe you can add a reconnect event to the network transport.

#

KcpTransport's Awake()

        client = new KcpClient(
            () => OnClientConnected.Invoke(),
            (message, channel) => OnClientDataReceived.Invoke(message, FromKcpChannel(channel)),
            () =>
            {
                if (!NetworkClient.isConnected)
                {
                    //TODO: Your timeout event
                }
                OnClientDisconnected?.Invoke();
            }, // may be null in StopHost(): https://github.com/MirrorNetworking/Mirror/issues/3708
            (error, reason) => OnClientError.Invoke(ToTransportError(error), reason),
            config
        );
pearl lantern
#

Will try that, thank you!