How can I get the PING (Latency) of a match before joining it as a Client?

Context: My multiplayer game uses Unity Relay to guarantee that players will be able to connect, and it also uses Unity Lobby to publicly display matches and their data. I’m currently trying to include game latency in the Lobby data, so as to be able to order the matches by lowest latency.

Problem: I’ve not been able to find a simple way to get the latency of a match. My plan was to ping the selected relay server as a host to get the “Host to Relay” latency, and then do the same thing as a Client to get the “Client to Relay” latency, and finally add them up to get the estimated total latency the Client would have. However, I had problems trying to achieve this. Here’s what I’ve tried so far:

  • Pinging The Relay IP: From the host side, I was able to get the Relay endpoint IP, so I tried using the simple Ping object to send a ping message. Unfortunately, the packet never arrived back, I assume the Relay servers drop normal ping messages :frowning:
  • Sending a PING message via the Unity Services Web APIs: I tried manually using the web API to send ping messages, I tried using the Relay message protocol or the Qos service for this… However, I kept getting “unauthorized” errors. I guess I’m doing something wrong here, It seems that I require a special key that it’s only accessible to the Organization owner for sending messages. Is that how it works? Or am I doing something wrong? My head hurts at this point… I also tried to get my credentials from my session in Unity Serives (since my game is done in Unity and I use the plugins and all), but I couldn’t access any tokens, I’ve only got my allocation secret key but I honestly don’t know how to use it, and I keep having trouble with the custom headers I need.

Question:

  • Is there any easy solution for my problem that I’m not seeing? This is taking me alot of time, and I might be missing something very simple and obvious. If I am, please let me know.
  • Should I keep going with the Web API route? Does anyone have any idea what I might be doing wrong here?

Thanks in advance…

Hi rodrigo_unity487
Regarding your question, we suggest using our QoS package as follows:

  • Depending on the region that the host will connect to, use the QoS package to get the host latency from the host to the QoS region
qosResultsForRegion = await QosService.Instance.GetSortedQosResultsAsync("relay", qosRegion.Value);
  • Add to the lobby data the region and the host latency

  • From the client retrieve the region from the lobby data and use it to get the client latency to the host region

  • Retrieve the host latency from the Lobby data

  • By adding the host latency and the client latency you should be able to get a good estimation on the latency of the connection between the host and the client through the relay in that region

I hope this helps,
R

2 Likes

This worked perfectly! Thank you very much!