Search Unity

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

Discussion in 'UNet' started by IvanHTN, Oct 15, 2016.

  1. IvanHTN

    IvanHTN

    Joined:
    Feb 12, 2016
    Posts:
    37
    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.
     
    Lohoris2 likes this.
  2. IvanHTN

    IvanHTN

    Joined:
    Feb 12, 2016
    Posts:
    37
    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:
    Code (CSharp):
    1. private bool connecting;
    2. private NetworkManager nm;
    3.  
    4. private void Start () {
    5.      connecting = false;
    6.      nm = GameObject.Find ("NetworkManager").getComponent<NetworkManager> ();
    7. }
    8.  
    9. public void startClientCustom () {
    10.     nm.StartClient ();
    11.     connecting = true;
    12. }
    13.  
    14. private void Update () {
    15.         if (connecting) {
    16.             Debug.log ("CONNECTING...");
    17.             if (!isNetworkActive) {
    18.                 nm.StopClient ();
    19.                 Debug.log ("CONNECTION FAILED");
    20.                 connecting = false;
    21.             }
    22.         }
    23. }
    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.
     
    Last edited: Oct 20, 2016
  3. Oberheim

    Oberheim

    Joined:
    Jun 4, 2020
    Posts:
    24
    YAAAAS ! Thanks very much <3 <3 <3