Search Unity

UNET HLAPI Host -- no callbacks when losing connectivity to Relay Server?

Discussion in 'UNet' started by MechEthan, Mar 13, 2017.

  1. MechEthan

    MechEthan

    Joined:
    Mar 23, 2016
    Posts:
    166
    TLDR: We really need a reliable, clean way to determine if the Host's Match is effectively dead due to networking issues. Any recommendations?

    Details:
    We currently have a problem where our users can Host a match successfully on their mobile phone, but they have terrible connectivity and no users can join or find the match.

    This would be fine if we had any idea that the Host had lost connectivity, but we don't. From the Host's perspective, everything is fine (because the Server is obviously running locally) -- so we don't get any OnServer/ClientDisconnect or OnServer/ClientError messages. But, the match-making server eventually delists the match, and the Host is no longer in touch with the Unity Relay Server.

    The only approach we have so far is to check for mass disconnects -- that is, if the Host has two or more users successfully connect before the Host's connectivity degrades, we make the assumption if all connected Client's suddenly disconnect it's because of the Host's network connection, and not the other way around. This is insufficient.

    Is there a safe/correct networking call we can make periodically to the relay server's IP address (discovered via MatchInfo.address) from the Host? The basic WWW request to check reachability won't work because the relay server is not an HTTP server. What parts of the LLAPI would I use to do this correctly?
     
  2. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187
    Hi,

    nothing simpler than that, write your own "keep alive" service using NetworkServerSimple and some messages inherited from MessageBase, you could use that service for more , like a login system or such.
    As always things sound often simpler than they are, but having your own ingame "ping" is not a wrong way.
     
    MechEthan likes this.
  3. MechEthan

    MechEthan

    Joined:
    Mar 23, 2016
    Posts:
    166
    Thanks Karsten, I might end up doing that.

    However, I did some more digging and found this: https://docs.unity3d.com/550/Docume...ng.NetworkTransport.ConnectAsNetworkHost.html

    "Calling this function sets the connection as the owner of the network group on the Relay server. This client should call ReceiveRelayEventFromHost periodically to be notified about connection/disconnection events to/from Relay server."

    Well, that sounds exactly like what I need!
    So let's see who is calling it and then I can hook into it somehow, right?
    https://bitbucket.org/Unity-Technol...=file-view-default#NetworkServerSimple.cs-201
    Code (csharp):
    1. // Lines #214 - 226:
    2. networkEvent = NetworkTransport.ReceiveRelayEventFromHost(m_ServerHostId, out error);
    3. if (NetworkEventType.Nothing != networkEvent)
    4. {
    5.     if (LogFilter.logDebug) { Debug.Log("NetGroup event:" + networkEvent); }
    6. }
    7. if (networkEvent == NetworkEventType.ConnectEvent)
    8. {
    9.     if (LogFilter.logDebug) { Debug.Log("NetGroup server connected"); }
    10. }
    11. if (networkEvent == NetworkEventType.DisconnectEvent)
    12. {
    13.     if (LogFilter.logDebug) { Debug.Log("NetGroup server disconnected"); }
    14. }
    Nope. They consume it and then throw it away. Now to investigate how I can use a locally modified version of their Networking library...

    UPDATE: Never mind, it seems the DisconnectEvent never gets sent... I get the ConnectEvent, but inducing 100% packet loss and/or complete connectivity loss doesn't cause anything to happen. I guess they don't expose this in the HLAPI because it doesn't appear to work.
     
    Last edited: Mar 14, 2017
  4. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187
    Just that you get me right, i want you to write your own "ping" on the low level API this is , your client has to send a small message to the "host" every few seconds and the host must answer this message if it does not answer then there is a serious network issue on the host.
     
    MechEthan likes this.
  5. MechEthan

    MechEthan

    Joined:
    Mar 23, 2016
    Posts:
    166
    Yes, I understood, and thank you for help and time!