How to measure packet loss percentage?

Options
We're adding some client side feedback for networking issues (much like in battlefield), icons such as high ping, packet loss etc. we want to show to the client so they know whats up with their connection.

Does bolt have a callback/method to get the amount of packet loss currently being experienced? Otherwise if it doesn't how can I check if bolt's packets have been lost or not so I can do failed packets divided by sent packets.

Cheers

Comments

  • stanchion
    Options
    We do not have that in the API right now, here is an example that gets you all the available info

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Game.GameCore
    {
    public abstract class NetworkStats
    {
    public abstract float Ping { get; }
    public int PingAsMilliseconds { get { return (int) (Ping * 1000f); } }

    public abstract float BytesPerSecondIn { get; }
    public abstract float BytesPerSecondOut { get; }

    public float KBytesPerSecondIn { get { return BytesPerSecondIn / 1024f; } }
    public float KBytesPerSecondOut { get { return BytesPerSecondOut / 1024f; } }

    public string KBytesPerSecondInString { get { return string.Format ("{0:0.00}", KBytesPerSecondIn); } }
    public string KBytesPerSecondOutString { get { return string.Format ("{0:0.00}", KBytesPerSecondOut); } }

    public string KBytesPerSecondInLongString { get { return string.Format ("{0:0.00} k/sec down", KBytesPerSecondIn); } }
    public string KBytesPerSecondOutLongString { get { return string.Format ("{0:0.00} k/sec up", KBytesPerSecondOut); } }

    public override string ToString()
    {
    return string.Format ("({0} ms) ({1:0.00} k/sec down) ({2:0.00} k/sec up)", PingAsMilliseconds, KBytesPerSecondIn, KBytesPerSecondOut);
    }
    }

    public class NetworkStatsClient : NetworkStats
    {
    public BoltConnection Connection { get; private set; }

    public override float Ping { get { return Connection.PingNetwork; } }

    public override float BytesPerSecondIn { get { return (float) Connection.BitsPerSecondIn / 8f; } }
    public override float BytesPerSecondOut { get { return (float) Connection.BitsPerSecondOut / 8f; } }

    public NetworkStatsClient (BoltConnection connection)
    {
    Connection = connection;
    }
    }

    public class NetworkStatsServer : NetworkStats
    {
    ///
    /// Total ping on the server is pointless.
    ///
    public override float Ping { get { return 0f; } }
    public override float BytesPerSecondIn { get { return GameManagerPlayers.Instance.ServerHandler.Players.Where (player => player.IsClientPlayer).Sum (player => player.NetStats.BytesPerSecondIn); } }
    public override float BytesPerSecondOut { get { return GameManagerPlayers.Instance.ServerHandler.Players.Where (player => player.IsClientPlayer).Sum (player => player.NetStats.BytesPerSecondOut); } }

    public NetworkStatsServer ()
    {
    }
    }
    }