Ping Client
Overview
The Ping Client is a utility class in the coherence SDK that allows you to measure network latency to coherence servers. It supports both UDP and TCP protocols and provides configurable timeout and cancellation token support for robust latency testing.
Due to using raw TCP/UDP sockets, currently PingClient does not support the WebGL platform.
Usage
When you fetch regions using RegionsService.FetchRegionsInfoAsync, you
receive both the available regions and their associated ping servers. This data can then be used in the PingClient in order to measure round-trip time to the respective regions:
PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
// Fetch information about regions available in our Project.
var regionsService = playerAccount.Services.Regions;
var regions = await regionsService.FetchRegionsAsync();
// Ping all available regions.
var pingResults = await PingClient.PingAsync(regions);
foreach (var ping in pingResults)
{
if (ping.Success)
{
Debug.Log($"Region {ping.Region} has round-trip time of {ping.RoundTripMs}ms");
}
else
{
Debug.LogWarning($"Failed to ping region {ping.Region}: {ping.Error}");
}
}Notes
PingClient.PingAsyncoptionally accepts:PingProtocolenum to specify which protocol to use for pingingTimeout value in milliseconds to specify the maximum time spent pinging
Cancellation token used for aborting the ping operation
The result is an average over multiple pings made internally within a single call to
PingClient.PingAsyncMultiple regions are pinged in parallel for efficiency
Last updated
Was this helpful?

