ServerPingProfiler
A class in Root.Township, Alta.Utilities.Profiling.NetworkTransportMetrics.ABTesting.
Networked behaviour that measures round-trip time to every player by sending a ping event and timing the reply. Server reads the result through ServerProfilingData.AveragePing; reach it through the static Instance.
- Listed in Utilities and other Alta namespaces
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
ServerPingProfiler() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
5 private and internal fields
| Member | What it is |
|---|---|
private const long maxPing | Constant 5000. Not used in this class. |
private readonly Dictionary<int, float> playerIdToPingMap | Last measured round trip in seconds, keyed by player identifier. |
private readonly Dictionary<int, float> playerIdToPingStartTimeMap | Time each player's last ping was sent, keyed by player identifier. |
private MethodSync syncPingClientToServer | Method sync (NetworkedEventB) the client uses to answer a ping. |
private MethodSync syncPingServerToClient | Method sync (NetworkedEventA) the server uses to send a ping. |
Properties
| Member | What it is |
|---|---|
static ServerPingProfiler Instance { get; private set; } | The single profiler in the scene, set in Initialize. |
Methods
| Member | What it is |
|---|---|
float GetAveragePing() | Server: sends a new ping to every player, then returns the average of the last measured round trips in seconds, or -1 if none yet. |
override void Initialize() | Sets the static Instance (logs an error if one already exists) and creates the two ping MethodSync events. |
4 private and internal methods
| Member | What it is |
|---|---|
private static float GetTimeStamp() | Returns Time.realtimeSinceStartup, used to time pings. |
private void SendPingMessagesToConnectedClients() | Server: sends the ping event to each player in Player.AllPlayers. |
private void SyncPlayerPingClientToServer(IPlayer player, Stream stream) | Server side of the reply: works out the round trip from the stored start time and saves it for that player. |
private void SyncPlayerPingServerToClient(IPlayer player, Stream stream) | Ping event handler. When writing it stores the send time for the player; on a remote client it sends the reply event back. |