Search Unity

Question Dependency between UnityTransport.SetRelayServerData and NetworkManager.StartClient?

Discussion in 'Relay' started by soemyatmyat, Dec 16, 2022.

  1. soemyatmyat

    soemyatmyat

    Joined:
    Sep 20, 2022
    Posts:
    7
    Is there a dependency between
    NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(...)

    and

    NetworkManager.Singleton.StartClient();
    ?

    I am able to get the client started using Join Code from JoinAllocation.
    NetworkManager.Singleton.StartClient()
    returns True.

    But the client is definitely not connected to the host. Because on the host,
    NetworkManager.Singleton.ConnectedClientsList.Count
    returns 1 only.

    After awhile (30-40 seconds), on the client, I get an error message from Unity Transport stating "Failed to connect to server".


    Failed to connect to server.
    UnityEngine.Debug:LogError (object)
    Unity.Netcode.Transports.UTP.UnityTransport:ProcessEvent () (at Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/UnityTransport.cs:828)
    Unity.Netcode.Transports.UTP.UnityTransport:Update () (at Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/UnityTransport.cs:877)


    I am using Relay Unity Transport for Protocol Type and NetcodeforGameObject for multi-players support.
    How can we troubleshoot from here? I looked into UnityTransport.cs (https://github.com/Unity-Technologi...ects/Runtime/Transports/UTP/UnityTransport.cs) and the description there says: connection attempts has failed.

    But why?
     
  2. unity-ptrottier

    unity-ptrottier

    Unity Technologies

    Joined:
    Nov 2, 2021
    Posts:
    15
    Hello soemyatmyat,

    Do you get the same problem for these two scenarios:
    1. DTLS on both client and host
    2. UDP on both client and host

    Also, are you using the RelayServerData constructors when setting up UTP? They reduce the odds of mistake.

    e.g.:
    Code (CSharp):
    1.  
    2. var rsd = new RelayServerData(alloc, "udp");
    3. NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(rsd)
    4.  
    Cheers,
    Philippe
     
  3. soemyatmyat

    soemyatmyat

    Joined:
    Sep 20, 2022
    Posts:
    7
    Hi Philippe,

    I am using DTLS on both client and host.
    The funny thing is
    NetworkManager.Singleton.StartClient();
    started successfully.

    But transport throws "Failed to connect to server." error later causing the NetworkManager to shut down.

    I don't think Startclient should return true if Transport is still communicating with Relay Server to setup the connection.