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.

Usage

When you fetch regions using the cloudRooms.RefreshRegionsInfo methods, 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 rooms = playerAccount.Services.Rooms;
var regionsInfo = await rooms.RefreshRegionsInfoAsync();

// Ping all available regions.
var pingResults = await PingClient.PingAsync(regionsInfo);

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.PingAsync optionally accepts:

    • PingProtocol enum to specify which protocol to use for pinging

    • Timeout 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.PingAsync

  • Multiple regions are pinged in parallel for efficiency

Last updated

Was this helpful?