Is there a way to be notified when ConnectToRegionMaster fails?

Options
Hi, Is there a way to get notified if LoadBalancingClient.ConnectToMasterServer() fails (e.g. due to connection issues)?

Comments

  • Patrik
    Patrik
    edited August 2020
    Options
    Came up with this:
            private void Start()
            {
                _client.StateChanged += OnLoadBalancingClientStateChanged;
            }
    
            private void OnLoadBalancingClientStateChanged(ClientState previousState, ClientState state)
            {
                Debug.Log("Changing state from: " + previousState + ", to: " + state);
    
                if (previousState == ClientState.ConnectingToMasterServer && 
                    state == ClientState.ConnectedToMasterServer)
                {
                    Debug.Log("Connection succeeded!");
                }
    
                if (previousState == ClientState.ConnectingToMasterServer &&
                    state != ClientState.ConnectedToMasterServer)
                {
                    Debug.Log("Connection failed!");
                }
            }
    

    When calling _client.ConnectToRegionMaster("eu") I get the following state changes:

    PeerCreated -> ConnectingToNameServer

    Nothing else.
  • Patrik
    Options
    Tried doing:
            private void Start()
            {
                _client = new LoadBalancingClient();
                _client.AddCallbackTarget(this);
                _client.StateChanged += OnLoadBalancingClientStateChanged;
                _client.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
                _client.AppVersion = PhotonNetwork.NetworkingClient.AppVersion;
                _client.ConnectToRegionMaster("us");
            }
    
            private void OnLoadBalancingClientStateChanged(ClientState previousState, ClientState state)
            {
                Debug.Log("Changing state from: " + previousState + ", to: " + state);
    
                if (previousState == ClientState.ConnectingToMasterServer && 
                    state == ClientState.ConnectedToMasterServer)
                {
                    Debug.Log("Connection succeeded");
                }
    
                if (previousState == ClientState.ConnectingToMasterServer &&
                    state != ClientState.ConnectedToMasterServer)
                {
                    Debug.Log("Connection failed");
                }
            }
    

    I call _client.ConnectToRegionMaster("eu") and get:

    Changing state from: PeerCreated, to: ConnectingToNameServer

    Nothing else.
  • Tobias
    Options
    Check the result of Connect-calls. If it's false, the connect failed even before making an attempt.
    Then, implement IConnectionCallbacks. It has OnDisconnected, which is also called in cases where the connection is not entirely setup yet. The DisconnectReason helps identify the cause.

    If you use WebSockets, there are a few cases, which accidentally don't get you a callback. UDP, the preferred protocol should get you the callbacks. Sometimes a timeout is needed and this takes < 10 sec.
  • Tobias
    Options
    If you don't use the latest PUN 2, please update.
  • Patrik
    Options
    Using PUN2. Thanks looks like OnCustomAuthenticationFailed was called, I needed to set AuthValues on the LoadBalancingClient and not just the PhotonNetwork object.