Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Relay not connecting client when using dtls as connection type but working fine with udp

Discussion in 'Unity Transport' started by vaibhavssshukla, Jan 19, 2023.

  1. vaibhavssshukla

    vaibhavssshukla

    Joined:
    Apr 15, 2020
    Posts:
    2
    There is no problem when trying to start the host with netcode for gameobject but the client doesn't connect, neither does it show any error

    This is how i am creating a relay


    Code (CSharp):
    1. try
    2.         {
    3.             LobbyUI.Instance.HideLobbyCanvas();
    4.             Allocation allocation =  await RelayService.Instance.CreateAllocationAsync(1);
    5.             string joinCode= await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
    6.             RelayServerData relayServerData = new RelayServerData(allocation,"dtls");
    7.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
    8.             NetworkManager.Singleton.StartHost();
    9.             return joinCode;
    10.         }
    11.         catch (RelayServiceException e) {
    12.             LobbyUI.Instance.ShowLobbyCanvas();
    13.             Debug.Log(e);
    14.         }



    and this is how i am joining a relay
    Code (CSharp):
    1. try
    2.         {
    3.             Debug.Log(joinCode);
    4.             LobbyUI.Instance.HideLobbyCanvas();
    5.             JoinAllocation allocation= await RelayService.Instance.JoinAllocationAsync(joinCode);
    6.             RelayServerData relayServerData = new RelayServerData(allocation, "udp");
    7.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
    8.             NetworkManager.Singleton.StartClient();
    9.         }
    10.         catch (RelayServiceException e) {
    11.             LobbyUI.Instance.ShowLobbyCanvas();
    12.             Debug.Log(e);
    13.         }
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    Are your host and client on the same machine?

    If you wait a bit after starting the client, does it eventually show an error message? I think the default connection timeout is around a minute (you can change the values in the inspector under the 'Unity Transport' component).