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
  3. Dismiss Notice

Question Relay Server Expires (NGO)

Discussion in 'Netcode for GameObjects' started by Fraccas, Mar 11, 2024.

  1. Fraccas

    Fraccas

    Joined:
    Jul 10, 2014
    Posts:
    17
    Hello, I have a dedicated server running at all times using NGO, lobbies, and a relay server to allow WebGL. It seems like after some time the relay server expires and players can no longer join the server.

    What is the expiration period for a Relay and how do I keep it alive for extended periods?

    If this can't be done, is there a way to detect when the Relay server expires so I can restart it?



    According to the docs, the connection to the Relay is automatically kept alive in NGO.
    https://docs.unity.com/ugs/en-us/manual/relay/manual/keep-connection-alive

    For games with a lower message frequency, it’s important to keep the connection alive with a method that you regularly call, such as in the Update() loop. If you’re using Relay with NGO, the network manager (NetworkManager) keeps the connection alive automatically. However, it will only do so after you’ve successfully called StartClient or StartHost.

    Thanks,
    Fraccas
     
    Last edited: Mar 11, 2024
    alysonlupo likes this.
  2. Fraccas

    Fraccas

    Joined:
    Jul 10, 2014
    Posts:
    17
    For additional information, it appears the Relay tends to go offline during periods in which our US testers are not joining the server.

    I'm looking to determine how the dedicated server can detect that the Relay server is no longer alive.
     
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,174
  4. Fraccas

    Fraccas

    Joined:
    Jul 10, 2014
    Posts:
    17

    Attached Files:

  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,174
    but it also mentions if you have say a coroutine sending data it should. so your host can join as a client and send keepalives
     
  6. Fraccas

    Fraccas

    Joined:
    Jul 10, 2014
    Posts:
    17
    This appears to have resolved the issue.
    https://docs.unity.com/ugs/manual/relay/manual/relay-and-utp

    Code (CSharp):
    1.  
    2. // Create NetworkSettings using the Relay server data to keep relay alive
    3. var settings = new NetworkSettings();
    4. settings.WithRelayParameters(ref relayServerData);
    5.  
    6. // Create the Host's NetworkDriver from the NetworkSettings.
    7. var hostDriver = NetworkDriver.Create(settings);
    8.  
    9. // Bind to the Relay server.
    10. if (hostDriver.Bind(NetworkEndpoint.AnyIpv4) != 0)
    11. {
    12.         Debug.LogError("Host client failed to bind");
    13. }
    14. else
    15. {
    16.         if (hostDriver.Listen() != 0)
    17.         {
    18.             Debug.LogError("Host client failed to listen");
    19.         }
    20.         else
    21.         {
    22.             Debug.Log("Host client bound to Relay server");
    23.         }
    24. }
    25. // End Create NetworkSettings using the Relay server data to keep relay alive
    26.