Can't re-enter the game room

Options
When I try to re-enter the game room after staying in the lobby for a while, nothing happens and I can't get in the game room. First entering and re-entering use the same Unity source code.
Another case... I put the game on hold by pressing Home button(Android). I keep it on hold for some time.
In this case, mostly the game comes back to the lobby without any human actions.
In this case, I can't re-enter the game room either. I have to quit the game and start it again to get in.

One more question. I sometimes get this error at the beginning, saying...
Connect() to 'ns.exitgames.com' failed: System.Net.Sockets.SocketException: No such host is known...

I haven't found any clear explanations about this. Can anyone enlighten me?

Thanks for any help. :)

Comments

  • mhhk88
    Options
    Sorry One more question. I'm about to launch a network game, so I'm nervous. :)

    An network object sometimes gets kicked out of the game without any reasons.
    It was just moving around. No fights, no collisions.
    Any possible reasons?
  • mhhk88
    mhhk88
    edited August 2018
    Options
    The Unity code for the 1st case(enter the game room) is like this...
    public void PressPlayBtn() {
    		//if (!isJoinedLobby) return;
    		bool isJoined = false;
    
    		foreach(RoomInfo ri in PhotonNetwork.GetRoomList()) {
    			if (ri.PlayerCount < ri.MaxPlayers) {
    				PhotonNetwork.JoinRoom(ri.Name);
    				isJoined = true;
    				break;
    			}
    		}
    
    		if (!isJoined) {
    			string roomName = "SF" + Random.Range(0, 100000).ToString("D6");
    			RoomOptions roomOptions = new RoomOptions();
    			roomOptions.IsOpen = true;
    			roomOptions.IsVisible = true;
    			roomOptions.MaxPlayers = 10;
    
    			PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
    		}
    	}
    Please help me.
  • mhhk88
    Options
    Would any Photon engineers help me on this? Thanks in advance for any help :)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @mhhk88,

    The issue is not clear to me.
    Try to explain and one question at a time preferably for each question start a new separate forum discussion.
    Also, make sure to search the forum first to see if your question wasn't answered before.

    Also, I have revisited an old discussion of yours and this one, from the code snippet I think you are doing random matchmaking the wrong way

    Try something like:
    public void OnClickJoinRandomRoom() 
    {
        PhotonNetwork.JoinRandomRoom();
    }
    
    private void OnPhotonRandomJoinFailed(object[] codeAndMsg)
    {
          CreateNewRoom();
    }
    
    private void CreateNewRoom() 
    {
          string roomName = "SF" + Random.Range(0, 100000).ToString("D6");
          RoomOptions roomOptions = new RoomOptions();
          roomOptions.IsOpen = true;
          roomOptions.IsVisible = true;
          roomOptions.MaxPlayers = 10;
    
          PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
    }
  • mhhk88
    Options
    I will try your code and come back here with the results. Thanks.
  • mhhk88
    Options
    @JohnTube I tried it with your code. It still happens.
    If I don't have any game rooms, OnPhotonRandomJoinFailed() is supposed to be called, right?
    But that callback was not called, and I couldn't get into any rooms neither.
    In this case, should I do something before calling PhotonNetwork.JoinRandomRoom() ?
  • mhhk88
    Options
    @JohnTube Some thoughts just flashed through my mind. In this case, which is I am unexpectedly kicked out of the game room after a long pause, I may not be on the lobby, even though I am on the lobby?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @mhhk88,

    I still don't understand what is the issue exactly?
    What error do you see in the console?

    if it's this one:
    Connect() to 'ns.exitgames.com' failed: System.Net.Sockets.SocketException: No such host is known...
    Then it means you cannot connect to Photon's name server because of a DNS issue or something else. Try another network or try connecting again maybe later.

    But you are also mentioning other problems.
    I recommend we tackle them one by one.
    Nevertheless, I will try to answer your questions.

    If I don't have any game rooms, OnPhotonRandomJoinFailed() is supposed to be called, right?
    Yes if no match can be found that callback should be triggered.
    should I do something before calling PhotonNetwork.JoinRandomRoom() ?
    You should be connected to Photon master server (connected to Photon and not joined to a room).
    I may not be on the lobby, even though I am on the lobby?
    It depends if you were disconnected from all Photon servers or just left the room and if AutoJoinLobby is enabled or not if you reconnect, etc.
  • mhhk88
    Options
    @JohnTube Maybe I am not able to make you understand my problem with my english skill. Sorry about that. I will try to explain again what happened to me as detailed as I could.
    I am playing a game. For some reasons, I am away from my phone. After a while, my phone is automatically locked so the game might be running in background from that time.
    I am back to my phone and try to play the same game again. Maybe because of long time passing, my game is back on lobby. So I try to start the game again using the 'OnClickJoinRandomRoom()' up here.
    But it doesn't start with no error message. OnPhotonRandomJoinFailed() is not called. (I am using the code you recommend in the 5th talk-box here) I wonder if I need different PUN APIs in this case.
    To play the game again, I have to quit the game and restart.
    It happens once in a while, not always.
    I hope you can guess what my problem is.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    I see.
    What is happening is the following:
    You get timeout disconnect because the app moves to the background or stays there too long.
    It depends on what you want to do when you get disconnected and how you create rooms.
    If you create rooms with PlayerTTL big enough to allow quick rejoins.
    Otherwise, you could just PhotonNetwork.Reconnect() and once connected join a room or a random one.
    You could use this QuickRejoin.cs by adding it to the scene, preferably attached to a GameObject that has DontDestroyOnLoad.
    It will help you recover from unexpected disconnects: reconnect and optionally rejoin.
  • mhhk88
    Options
    @JohnTube It's been OK since I used your recommendation. Thank you so much for your time^^