Пример #1
0
 /// <summary>
 /// NetManager constructor
 /// </summary>
 /// <param name="listener">Network events listener</param>
 /// <param name="maxConnections">Maximum connections (incoming and outcoming)</param>
 public NetManager(INetEventListener listener, int maxConnections)
 {
     socket                  = new NetSocket(ReceiveLogic);
     netEventListener        = listener;
     netEventsQueue          = new Queue <NetEvent>();
     netEventsPool           = new Stack <NetEvent>();
     NetPacketPool           = new NetPacketPool();
     NatPunchModule          = new NatPunchModule(socket);
     Statistics              = new NetStatistics();
     peers                   = new NetPeerCollection();
     connectingPeers         = new HashSet <IPEndPoint>(new IPEndPointComparer());
     this.maxConnections     = maxConnections;
     _connectedPeerListCache = new List <NetPeer>();
 }
Пример #2
0
        private NetPeer(NetManager netManager, IPEndPoint remoteEndPoint)
        {
            Statistics      = new NetStatistics();
            _packetPool     = netManager.NetPacketPool;
            _netManager     = netManager;
            _remoteEndPoint = remoteEndPoint;

            _avgRtt        = 0;
            _rtt           = 0;
            _pingSendTimer = 0;

            _reliableOrderedChannel   = new ReliableChannel(this, true);
            _reliableUnorderedChannel = new ReliableChannel(this, false);
            _sequencedChannel         = new SequencedChannel(this);
            _unreliableChannel        = new SimpleChannel(this);
            _reliableSequencedChannel = new ReliableSequencedChannel(this);

            _holdedFragments = new Dictionary <ushort, IncomingFragments>();

            _mergeData  = new NetPacket(PacketProperty.Merged, NetConstants.MaxPacketSize);
            _pongPacket = new NetPacket(PacketProperty.Pong, 0);
            _pingPacket = new NetPacket(PacketProperty.Ping, 0);
        }