[PUN2] Suddenly can't get 2 clients in the same room

Options
JoeStrout
JoeStrout
edited September 2018 in Photon Unity Networking (PUN)
I'm new to Photon, but everything was going just swimmingly until about an hour ago. Now all of a sudden, when I run my test code on 2 machines, each one acts as though it is the only one on the server. All counts and measures report there is only 1 player on the server, and 1 room in existence, and each one goes ahead and creates its own room.

It's not a timing issue; I have one client connected tens of seconds, or even minutes, before the other. And neither client receives an OnDisconnected until I purposely quit, so I don't think it's a premature disconnect either.

The code is simple:
	public override void OnConnectedToMaster() {
Debug.Log("OnConnectedToMaster() was called by PUN. Joining a random room.");

Debug.Log("CountOfPlayersOnMaster: " + PhotonNetwork.CountOfPlayersOnMaster
+ "; CountOfPlayersInRooms: " + PhotonNetwork.CountOfPlayersInRooms
+ "; CountOfRooms: " + PhotonNetwork.CountOfRooms);
PhotonNetwork.JoinRandomRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message) {
Debug.LogWarning("OnJoinRandomRoomFailed(" + returnCode + ", " + message + ")");
PhotonNetwork.CreateRoom("");
}
public override void OnJoinedRoom() {
Debug.Log("OnJoinedRoom! I am actor number " + PhotonNetwork.LocalPlayer.ActorNumber
+ ", and there are " + PhotonNetwork.CurrentRoom.PlayerCount + " player(s), including me");
...
}
And when I run this, I see (on each client, regardless of order, timing, etc.):
  • CountOfPlayersOnMaster: 0; CountOfPlayersInRooms: 0; CountOfRooms: 0
  • OnJoinRandomRoomFailed(32760, No match found)
  • OnJoinedRoom! I am actor number 1, and there are 1 player(s), including me
Again, all this was working fine an hour ago; since then, it fails every time. I've been tinkering with code that doesn't run until much later (syncing some Photon Views), so I don't see how I could have broken it — and anyway, the code above should be all the code involved, and it's dead simple.

How do I go about debugging this?

Comments

  • JoeStrout
    Options
    More info: I decided to try explicitly sharing a room by name. So I changed OnConnectedToMaster to call
    PhotonNetwork.JoinRoom("WTF");
    , and added an OnJoinRoomFailed override that calls
    PhotonNetwork.CreateRoom("WTF");
    .

    The result? Each client now gets an OnJoinRoomFailed callback, and cheerfully creates and joins its own WTF room, without ever seeing any hint of the other. :'(
  • JoeStrout
    JoeStrout
    edited August 2018
    Options
    Still more info. It occurred to me that the two must be connecting to different servers. Logging the NetworkingClient.GameServerAddress, they are indeed different: 50.97.199.75:5056 on one machine, but 169.54.14.101:5056 on the other.

    So now the question is, why? Why am I suddenly being given two different game servers? Working backwards, in OnConnected, I log more stuff: on one client, I get:

    AppId: 53e6713c-976a-4869-89ef-0f45aea0adda; AppVersion: 1_2.0; CurrentServerAddress: 169.44.142.244:5055; MasterServerAddress: 169.44.142.244:5055

    while on the other:

    AppId: 53e6713c-976a-4869-89ef-0f45aea0adda; AppVersion: 1_2.0; CurrentServerAddress: 169.63.72.88:5055; MasterServerAddress: 169.63.72.88:5055

    So, same AppId and version, but somehow they connected to different master servers.

    ...I went back and added logging of CloudRegion. Sure enough, one device is using region 'usw' while the other is using region 'us'. Wtf?

    I'm making the connection using PhotonNetwork.ConnectUsingSettings(). In my settings, the server and port are left blank. Is that not the right thing to do?
  • TJDabs
    Options
    Thank goodness I found your post. I have been having the same issue and was very confused what was happening. I was able to connect players fine before but recently every time I build a client to test with the editor they are no longer able to get into a room together. It looks like it is the same issue you are having because when I explicitly tell it what region to connect to it will work again. Very strange that the editor would connect to a different region than the built client.
  • Yep. That's what it turned out to be for me — I worked around it by using a fixed region (for now, anyway).
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited September 2018
    Options
    Hi @JoeStrout, @TJDabs

    Thank you for choosing Photon!

    This may just be "random" due to little variations or exact same ping calculations.

    Theoretically, you could:

    - have the same exact ping to multiple regions from the same device. so its random, if you end up with different regions on clients connected to the same network.
    - different ping values for the same region on different devices (or different retries on the same device) connected to the same network.

    In the case of "us" and "usw" (or "ru" and "rue"), you could either make use of the regions whitelist online to select the ones you want and drop the others or connect to an explicit region.

    @TJDabs do you confirm you also had "us" and "usw" regions?
  • TJDabs
    Options
    @JohnTube Thanks for more info on the issue. Yes I believe I was also getting "us" and "usw". For now I just explicitly set my region to "us" in the Photon Server Settings and have been able to build and test fine since then.