Beispiel #1
0
        private string GetNetworkInfo()
        {
            if (DateTime.UtcNow >= _nextUpdate)
            {
                var info = NetworkProvider.GetConnectionInfo();

                double dataOut = (double)(info.BytesOut * 8L) / 1000000.0;
                double dataIn  = (double)(info.BytesIn * 8L) / 1000000.0;

                StringBuilder sb = new StringBuilder();
                sb.Append($"Latency: {info.Latency}ms");
                sb.Append($" | Pkt in/out(#/s): {info.PacketsIn}/{info.PacketsOut}");

                if (info.Ack.HasValue && info.AckSent.HasValue)
                {
                    sb.Append($" | Ack in/out(#/s): {info.Ack}/{info.AckSent}");
                }

                /* sb.Append($" | NACK's: {info.Nack}");
                 * sb.Append($" | Resends: {info.Resends}");
                 * sb.Append($" | Fails: {info.Fails}");*/
                sb.Append($" | THR in/out(Mbps): {dataIn:F}/{dataOut:F}");

                _lastString = sb.ToString();
                // _nextUpdate = DateTime.UtcNow.AddSeconds(0.5);
            }

            return(_lastString);
        }
Beispiel #2
0
        private string GetNetworkInfo()
        {
            var info = NetworkProvider.GetConnectionInfo();

            StringBuilder sb = new StringBuilder();

            sb.Append($"Latency: {info.Latency}");
            sb.Append($" | Ack: {info.AckSent} sent / {info.Ack} received");
            sb.Append($" | NACK's: {info.Nack}");
            sb.Append($" | Resends: {info.Resends}");
            sb.Append($" | Fails: {info.Fails}");

            return(sb.ToString());
        }
Beispiel #3
0
        private string GetNetworkInfo()
        {
            var info = NetworkProvider.GetConnectionInfo();

            //double dataOut = (double) (info.BytesOut * 8L) / 1000000.0;
            //double dataIn  = (double) (info.BytesIn * 8L) / 1000000.0;
            double dataOut = (double)(info.BytesOut) / 1000.0;
            double dataIn  = (double)(info.BytesIn) / 1000.0;

            StringBuilder sb = new StringBuilder();

            sb.Append($"Latency: {info.Latency}ms");
            sb.Append($" | Pkt in/out(#/s): {info.PacketsIn}/{info.PacketsOut}");

            //   if (info.Ack.HasValue && info.AckSent.HasValue)
            {
                sb.Append($" | Ack in/out(#/s): {info.Ack}/{info.AckSent}");
            }

            /* sb.Append($" | NACK's: {info.Nack}");
             * sb.Append($" | Resends: {info.Resends}");
             * sb.Append($" | Fails: {info.Fails}");*/
            sb.Append($" | THR in/out(Kbps): {dataIn:F2}/{dataOut:F2}");

            // WarningElement.IsVisible = info.State != ConnectionInfo.NetworkState.Ok;

            if (info.State != ConnectionInfo.NetworkState.Ok)
            {
                WarningElement.IsVisible = true;

                switch (info.State)
                {
                case ConnectionInfo.NetworkState.OutOfOrder:
                    WarningElement.Text = "Warning: Datagram out of order!";

                    break;

                case ConnectionInfo.NetworkState.Slow:
                    WarningElement.Text = "Warning: Slow networking detected!";

                    break;

                case ConnectionInfo.NetworkState.HighPing:
                    WarningElement.Text = "Warning: High latency detected, this may cause lag.";

                    break;

                case ConnectionInfo.NetworkState.PacketLoss:
                    WarningElement.Text = "Warning: Packet loss detected!";

                    break;
                }

                if (_state)
                {
                    WarningElement.TextColor = TextColor.Yellow;
                }
                else
                {
                    WarningElement.TextColor = TextColor.Red;
                }

                _state = !_state;
            }
            else
            {
                WarningElement.IsVisible = false;
            }

            _lastString = sb.ToString();
            // _nextUpdate = DateTime.UtcNow.AddSeconds(0.5);

            return(_lastString);
        }