예제 #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)
        {
            _logicThread = new Thread(UpdateLogic)
            {
                Name = "LogicThread", IsBackground = true
            };
            _socket           = new NetSocket(ReceiveLogic);
            _netEventListener = listener;
            _netEventsQueue   = new SwitchQueue <NetEvent>();
            _netEventsPool    = new Stack <NetEvent>();
            NetPacketPool     = new NetPacketPool();
            NatPunchModule    = new NatPunchModule(this);
            Statistics        = new NetStatistics();
            _peers            = new NetPeerCollection(maxConnections);
            _connectingPeers  = new HashSet <NetEndPoint>();
            _maxConnections   = maxConnections;
            _updateTimeFilter = new long[3];

            // Precreate all needed Merge Packets
            for (int i = 0; i < maxConnections * 3; ++i)
            {
                NetPacket p = NetPacketPool.Get(PacketProperty.Sequenced, 0, NetConstants.MaxPacketSize);
                p.Recycle();
            }
        }
 /// <summary>
 /// NetManager constructor
 /// </summary>
 /// <param name="listener">Network events listener</param>
 public NetManager(INetEventListener listener)
 {
     _socket                 = new NetSocket(this);
     _netEventListener       = listener;
     _netEventsQueue         = new Queue <NetEvent>();
     _netEventsPool          = new Stack <NetEvent>();
     NetPacketPool           = new NetPacketPool();
     NatPunchModule          = new NatPunchModule(_socket);
     Statistics              = new NetStatistics();
     _peers                  = new NetPeerCollection();
     _connectedPeerListCache = new List <NetPeer>();
 }
예제 #3
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());
     _maxConnections         = maxConnections;
     _connectedPeerListCache = new List <NetPeer>();
 }
예제 #4
0
        /// <summary>
        /// NetManager constructor
        /// </summary>
        /// <param name="listener">Network events listener</param>
        /// <param name="maxConnections">Maximum connections (incoming and outcoming)</param>
        /// <param name="connectKey">Application key (must be same with remote host for establish connection)</param>
        public NetManager(INetEventListener listener, int maxConnections, string connectKey)
        {
            _logicThread      = new NetThread("LogicThread", DefaultUpdateTime, UpdateLogic);
            _socket           = new NetSocket(ReceiveLogic);
            _netEventListener = listener;
            _flowModes        = new List <FlowMode>();
            _netEventsQueue   = new Queue <NetEvent>();
            _netEventsPool    = new Stack <NetEvent>();
            _netPacketPool    = new NetPacketPool();
            NatPunchModule    = new NatPunchModule(this);

            _connectKey     = connectKey;
            _peers          = new NetPeerCollection(maxConnections);
            _maxConnections = maxConnections;
            _connectKey     = connectKey;
        }
예제 #5
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)
 {
     _logicThread = new Thread(UpdateLogic)
     {
         Name = "LogicThread", IsBackground = true
     };
     _socket           = new NetSocket(ReceiveLogic);
     _netEventListener = listener;
     _netEventsQueue   = new Queue <NetEvent>();
     _netEventsPool    = new Stack <NetEvent>();
     NetPacketPool     = new NetPacketPool();
     NatPunchModule    = new NatPunchModule(this);
     Statistics        = new NetStatistics();
     _peers            = new NetPeerCollection(maxConnections);
     _connectingPeers  = new HashSet <NetEndPoint>();
     _maxConnections   = maxConnections;
 }