Search Unity

NoOpenLobbies Found after restarting game.

Discussion in 'Lobby' started by Jeel_Patel, Dec 12, 2022.

  1. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
    So i have made this server/client system where we start server on a computer and then my Quest 2 is connected as client. I am using Relay to connect over regions. The app can connect to host/server for first time, but after closing and playing again throws this error. To solve this I have to restart server (close and restart the application) which I don't want, I want player to connect anytime to this lobby. I have searched through multiple forums but not able to find solution so starting new thread.
    upload_2022-12-12_13-10-52.png
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @Jeel_Patel , I'd recommend to open a ticket through the Unity Dashboard. You'll easily get a direct reply from the lobby team there
     
  3. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    @Jeel_Patel - When you close the app and play again, is the client explicitly removing themselves from the Lobby. If you don't do that, the Lobby service has no way of automatically detecting that your game client has disconnected, so the player is probably still in the Lobby. Then when you start up the app again, it's unable to find any available lobbies to Join because you're already a member in the only lobby that's available.

    You can use the Get Joined Lobbies API to see if you're already connected to any lobbies and either disconnect (so you can connect to a new one) or just use that lobby info and pretend that you never left.
     
  4. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
    Thank you @veleek_unity , seems like i got past to that error, however now i am facing this HttpException. Im anot able to debug as its not coming through my code. I would need further help!
     
    Last edited: Dec 13, 2022
  5. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
  6. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    Based on the error, it looks like you're using a Relay Join Code that the Relay service doesn't know about. Lobby Join Code is not the same as Relay Join Code. Are you using the Lobby Join Code to connect to a Relay?

    You must have a client create a Relay (often the host of the lobby, but not required) and then have them share that information with the rest of the lobby members so they can connect themselves: https://docs.unity.com/lobby/relay-integration.html.
     
  7. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
    Code (CSharp):
    1.  
    2. public async void JoinAdminLobby()
    3.     {
    4.         Debug.Log("Looking for admin lobby...");
    5.         try
    6.         {
    7.             // Looking for a lobby
    8.  
    9.             // Add options to the matchmaking (mode, rank, etc..)
    10.             QuickJoinLobbyOptions options = new QuickJoinLobbyOptions();
    11.  
    12.             // Quick-join a random lobby
    13.             lobby = await LobbyService.Instance.QuickJoinLobbyAsync(options);
    14.  
    15.             connectedClients = lobby.Players.Count;
    16.             Debug.Log("Joined Admin lobby: " + lobby.Name);
    17.             Debug.Log("Lobby Players: " + lobby.Players.Count);
    18.  
    19.             // Retrieve the Relay code previously set in the create match
    20.             string joinCode = lobby.Data["joinCode"].Value;
    21.  
    22.             Debug.Log("Received code: " + joinCode);
    23.  
    24.             JoinAllocation allocation = await Relay.Instance.JoinAllocationAsync(joinCode);
    25.  
    26.             Debug.Log("CODE: Relay allocation finished");
    27.  
    28.             // Create Object
    29.             joinData = new RelayJoinData
    30.             {
    31.                 Key = allocation.Key,
    32.                 Port = (ushort)allocation.RelayServer.Port,
    33.                 AllocationID = allocation.AllocationId,
    34.                 AllocationIDBytes = allocation.AllocationIdBytes,
    35.                 ConnectionData = allocation.ConnectionData,
    36.                 HostConnectionData = allocation.HostConnectionData,
    37.                 IPv4Address = allocation.RelayServer.IpV4
    38.             };
    39.  
    40.             string relayJoinCode = await Relay.Instance.GetJoinCodeAsync(allocation.AllocationId);
    41.             PlayerPrefs.SetString("RelayJoinCode", relayJoinCode);
    42.  
    43.             // Set transport data
    44.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(
    45.                 joinData.IPv4Address,
    46.                 joinData.Port,
    47.                 joinData.AllocationIDBytes,
    48.                 joinData.Key,
    49.                 joinData.ConnectionData,
    50.                 joinData.HostConnectionData);
    51.  
    52.             // Finally start the client
    53.             Debug.Log("CODE: Relay DateSetting finished");
    54.             NetworkManager.Singleton.StartClient();
    55.  
    56.             //Spawn network player
    57.             //SpawnPlayer();     //Wait for login scene to spawn on successful login
    58.  
    59.             // Trigger events Here
    60.             isConnectedToLobby = true;
    61.  
    62.             //FindObjectOfType<NetworkAdmin>().SpawnPlayerServerRpc();
    63.             Debug.Log("CODE: Joining Finished");
    64.  
    65.         }
    66.         catch (LobbyServiceException e)
    67.         {
    68.             // If we don't find any lobby
    69.  
    70.             Debug.Log("Cannot find admin lobby: " + e + ",Retrying");
    71.  
    72.             var lobbyIds = await LobbyService.Instance.GetJoinedLobbiesAsync();
    73.             Debug.Log("Current lobbies are : " + lobbyIds.ToArray().Length);
    74.             if (lobbyIds.ToArray().Length > 0)
    75.             {
    76.                 Debug.Log("Player is in lobby: " + lobbyIds.ToArray()[0]);
    77.                 StartCoroutine(RetryJoinLobby(lobbyIds.ToArray()[0]));
    78.             }
    79.             /*
    80.             if (lobbyIds.ToArray().Length > 0)
    81.             {
    82.                 JoinExistingLobby(lobbyIds.ToArray()[0]);
    83.             }
    84.             else
    85.             {
    86.                 StartCoroutine(RetryJoinLobby(lobbyIds.ToArray()[0]));
    87.             }
    88.             */
    89.         }
    90.     }
    91.  
    92. async void JoinExistingLobby(string lobbyId)
    93.     {
    94.         //JoinAdminLobby();
    95.         try
    96.         {
    97.             // Looking for a lobby
    98.  
    99.             // Add options to the matchmaking (mode, rank, etc..)
    100.             QuickJoinLobbyOptions options = new QuickJoinLobbyOptions();
    101.  
    102.             // Quick-join a random lobby
    103.             lobby = await LobbyService.Instance.ReconnectToLobbyAsync(lobbyId);
    104.             //lobby = await LobbyService.Instance.QuickJoinLobbyAsync(options);
    105.  
    106.             connectedClients = lobby.Players.Count;
    107.             Debug.Log("Joined Admin lobby: " + lobby.Name);
    108.             Debug.Log("Lobby Players: " + lobby.Players.Count);
    109.  
    110.             // Retrieve the Relay code previously set in the create match
    111.             string joinCode = lobby.Data["joinCode"].Value;
    112.  
    113.             Debug.Log("Received code: " + joinCode);
    114.  
    115.             JoinAllocation allocation = await Relay.Instance.JoinAllocationAsync(joinCode);
    116.  
    117.             Debug.Log("CODE: Relay allocation finished");
    118.  
    119.             // Create Object
    120.             joinData = new RelayJoinData
    121.             {
    122.                 Key = allocation.Key,
    123.                 Port = (ushort)allocation.RelayServer.Port,
    124.                 AllocationID = allocation.AllocationId,
    125.                 AllocationIDBytes = allocation.AllocationIdBytes,
    126.                 ConnectionData = allocation.ConnectionData,
    127.                 HostConnectionData = allocation.HostConnectionData,
    128.                 IPv4Address = allocation.RelayServer.IpV4
    129.             };
    130.             // Set transport data
    131.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(
    132.                 joinData.IPv4Address,
    133.                 joinData.Port,
    134.                 joinData.AllocationIDBytes,
    135.                 joinData.Key,
    136.                 joinData.ConnectionData,
    137.                 joinData.HostConnectionData);
    138.  
    139.             // Finally start the client
    140.             Debug.Log("CODE: Relay DateSetting finished");
    141.             NetworkManager.Singleton.StartClient();
    142.  
    143.             //Spawn network player
    144.             //SpawnPlayer();
    145.             //Wait for login scene to spawn on successful login
    146.  
    147.             // Trigger events Here
    148.             isConnectedToLobby = true;
    149.  
    150.             //FindObjectOfType<NetworkAdmin>().SpawnPlayerServerRpc();
    151.             Debug.Log("CODE: Joining Finished");
    152.  
    153.         }
    154.         catch (LobbyServiceException e)
    155.         {
    156.             // If we don't find any lobby
    157.             Debug.LogError("Cannot find admin lobby: " + e + ",Retrying in 5 seconds");
    158.             StartCoroutine(RetryJoinLobby(lobbyId));
    159.         }
    160.     }
     
  8. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
    @veleek_unity SO on first load, its able to find and connect to lobby (here on line 24, im using retrieve code) but in JoinExistingLobby() im getting the error, seems like you're right, but how come it is working on JoinAdminLobby() ? but not in JoinExistingLobby()?
    Could you tell me how to do get relay join code in JoinExistingLobby() ?
     
  9. Jeel_Patel

    Jeel_Patel

    Joined:
    Jun 25, 2014
    Posts:
    7
    Okay, i found a work around, but not sure it its ideal or not.
    So whenever i restart my application for reconnection, its finding 2 lobbies (don't know why?). So it didn't work before because i was getting code for first lobby found. Now if i query code for last lobby found and use that code to reconnect lobby through relay, its working!!.
    Curious to know if its a bug, or its how its supposed to be?