예제 #1
0
 /// <summary>
 ///     Creates an instance of this object.
 /// </summary>
 public NetworkStats(NetPeerStatistics statistics)
 {
     SentBytes       = statistics.SentBytes;
     ReceivedBytes   = statistics.ReceivedBytes;
     SentPackets     = statistics.SentPackets;
     ReceivedPackets = statistics.ReceivedPackets;
 }
        /// <summary>
        /// Gets a <see cref="NetPeerStatisticsSnapshot"/> containing the changes in values in the <see cref="NetPeerStatistics"/>
        /// since the given <see cref="NetPeerStatisticsSnapshot"/> was made.
        /// </summary>
        /// <param name="a">The current <see cref="NetConnectionStatistics"/> containing the up-to-date values.</param>
        /// <param name="b">The <see cref="NetPeerStatisticsSnapshot"/> containing the base values.</param>
        /// <returns>A <see cref="NetPeerStatisticsSnapshot"/> containing the changes in values in the <see cref="NetPeerStatistics"/>
        /// since the given <see cref="NetPeerStatisticsSnapshot"/> was made.</returns>
        public static NetPeerStatisticsSnapshot Diff(NetPeerStatistics a, NetPeerStatisticsSnapshot b)
        {
            var ret = new NetPeerStatisticsSnapshot(a.ReceivedBytes - b.ReceivedBytes, a.ReceivedPackets - b.ReceivedPackets,
                                                    a.ReceivedMessages - b.ReceivedMessages, a.SentBytes - b.SentBytes, a.SentPackets - b.SentPackets,
                                                    a.SentMessages - b.SentMessages);

            return(ret);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetPeerStatisticsSnapshot"/> class.
        /// </summary>
        /// <param name="stats">The <see cref="NetPeerStatistics"/> to copy the values from.</param>
        public NetPeerStatisticsSnapshot(NetPeerStatistics stats)
        {
            _recvBytes   = stats.ReceivedBytes;
            _recvPackets = stats.ReceivedPackets;
            _recvMsg     = stats.ReceivedMessages;

            _sentBytes   = stats.SentBytes;
            _sentPackets = stats.SentPackets;
            _sentMsg     = stats.SentMessages;
        }
예제 #4
0
 /// <summary>
 /// NetPeer constructor
 /// </summary>
 public NetPeer(NetPeerConfiguration config)
 {
     m_configuration = config;
     m_statistics = new NetPeerStatistics(this);
     m_releasedIncomingMessages = new NetQueue<NetIncomingMessage>(4);
     m_unsentUnconnectedMessages = new NetQueue<NetTuple<NetEndPoint, NetOutgoingMessage>>(2);
     m_connections = new List<NetConnection>();
     m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>();
     m_handshakes = new Dictionary<NetEndPoint, NetConnection>();
     m_senderRemote = (EndPoint)new NetEndPoint(IPAddress.Any, 0);
     m_status = NetPeerStatus.NotRunning;
     m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>();
 }
예제 #5
0
 public static ConnectionStatistics Convert(NetPeerStatistics n, float rtt)
 {
     if (n != null)
     {
         ConnectionStatistics c = new ConnectionStatistics(
             n.ReceivedPackets, n.ReceivedBytes,
             n.SentPackets, n.SentBytes,
             n.ReceivedBytes, n.SentBytes);
         c.RoundTripTime = rtt;
         return(c);
     }
     else
     {
         ConnectionStatistics c = new ConnectionStatistics();
         c.RoundTripTime = rtt;
         return(c);
     }
 }