Can't connect (clientTimeout)

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

Answers

  • 1.
    if there is no room available you should create it or display the message that there is no room available.
    script does not check whether it is even available
    2.on connected to master is called when it is connected successfully, so if (isConnecting) is not needed
    btw
    and also make a region selection
    sometimes it switches me between eu and ru
    and does not show available rooms :wink:
  • Fa6exFa6ex
    edited August 13
    Nori_SC said:

    1.
    if there is no room available you should create it or display the message that there is no room available.
    script does not check whether it is even available
    2.on connected to master is called when it is connected successfully, so if (isConnecting) is not needed
    btw
    and also make a region selection
    sometimes it switches me between eu and ru
    and does not show available rooms :wink:

    First of all, thanks for answering.

    The isConnecting variable serves to prevent the player from connecting right after disconnecting (for example, by leaving the room). Also in the PUN connection settings (the one used by ConnectUsingSettings()) the region is set to eu. This code was pretty much copied and pasted from the PUN Basics Tutorial.

    The problem with all of this is I can't even connect, as OnConnectedToMaster isn't called. OnDisconnected is called instead, with DisconnectCause being clientTimeout.
  • Well, after a long, long time of floundering, I still haven't found out why exactly I can't connect. However, the problem was fixed after using CCleaner, so there's that.
Sign In or Register to comment.