(Solved) [UNET] When clients fails to connect exception is shown?

Hi everyone,

I have my network manager and i’m doing a custom UI for it. I have two buttons and a input field where address has to be entered, quite simple.

  • The host button calls NetworkManager.StartHost ().
  • The client button changes NetworkManager.networkAddress based on the input field value and calls NetworkManager.StartClient ().

The problem is that if there is no host at the address i’m getting two exceptions in the editor:

  • DNS resolution failed 11001
  • UNET client error connect error: 11

How i can prevent exceptions from showin in editor?
And how i can know StartClient () has failed to connect? void OnFailedToConnect function seems to not be called, but i suspect this can be related to the exceptions.

1 Like

Okey, after several days and reading a lot of information i got to a solution.

The only way i have found to show an error to the player according to the failed result of the NetworkManager.StartClient () method is this:

private bool connecting;
private NetworkManager nm;

private void Start () {
     connecting = false;
     nm = GameObject.Find ("NetworkManager").getComponent<NetworkManager> ();
}

public void startClientCustom () {
    nm.StartClient ();
    connecting = true;
}

private void Update () {
        if (connecting) {
            Debug.log ("CONNECTING...");
            if (!isNetworkActive) {
                nm.StopClient ();
                Debug.log ("CONNECTION FAILED");
                connecting = false;
            }
        }
}

So if connection to host fails isNetworkActive get’s set to false after some time. The only way i have found is to check it until it get’s false.

Hope this saves time for someone else.

4 Likes

YAAAAS ! Thanks very much <3 <3 <3