Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

Can't connect (clientTimeout)

$
0
0
I'm sure there's something ridiculously simple that I'm missing which I'm going to beat myself over afterwards, but I can't for the life of me figure out why I can't connect to Photon Cloud on my game. I get the clientTimeout DisconnectCause from the OnDisconnected callback. The demo provided with the PUN 2 unity package doesn't get this error. However, if I do that same on a new project, neither the demo or my game can connect. Both get the clientTimeout warning. Here's my code:
public void Connect()
    {
        Debug.Log("Connecting...");
        // keep track of the will to join a room, because when we come back from the game we will get a callback that we are connected, 
        // so we need to know what to do then
        isConnecting = true;
        // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
        if (PhotonNetwork.IsConnected)
        {
            // #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one.
            PhotonNetwork.JoinRandomRoom();
            
        }
        else
        {
            // #Critical, we must first and foremost connect to Photon Online Server.
            PhotonNetwork.GameVersion = gameVersion;
            PhotonNetwork.ConnectUsingSettings();
        }
    }

    

    public override void OnConnectedToMaster()
    {
        Debug.Log("Connected to " + PhotonNetwork.CloudRegion);
        
        
        // we don't want to do anything if we are not attempting to join a room. 
        // this case where isConnecting is false is typically when you lost or quit the game, when this level is loaded, OnConnectedToMaster will be called, in that case
        // we don't want to do anything.
        if (isConnecting)
        {
            // #Critical: The first we try to do is to join a potential existing room. If there is, good, else, we'll be called back with OnJoinRandomFailed()  
            PhotonNetwork.JoinRandomRoom();
            Debug.Log("Joined room " + PhotonNetwork.CurrentRoom.Name);
        }
    }

    public override void OnDisconnected(DisconnectCause cause)
    {
        Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
    }
The Connect() function is called through a UI button

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>