Exemplo n.º 1
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;
            _netEventsQueue   = new Queue <NetEvent>();
            _netEventsPool    = new Stack <NetEvent>();
            _netPacketPool    = new NetPacketPool();
            NatPunchModule    = new NatPunchModule(this);
            Statistics        = new NetStatistics();

            ConnectKey      = connectKey;
            _peers          = new NetPeerCollection(maxConnections);
            _maxConnections = maxConnections;
            ConnectKey      = connectKey;
        }
Exemplo n.º 2
0
        internal NetPeer(NetManager peerListener, NetEndPoint remoteEndPoint, long connectId)
        {
            Statistics      = new NetStatistics();
            _packetPool     = peerListener.PacketPool;
            _peerListener   = peerListener;
            _remoteEndPoint = remoteEndPoint;

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

            _reliableOrderedChannel   = new ReliableChannel(this, true);
            _reliableUnorderedChannel = new ReliableChannel(this, false);
            _sequencedChannel         = new SequencedChannel(this);
            _simpleChannel            = new SimpleChannel(this);

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

            _mergeData = _packetPool.Get(PacketProperty.Merged, NetConstants.MaxPacketSize);

            //if ID != 0 then we already connected
            _connectAttempts = 0;
            if (connectId == 0)
            {
                _connectId = DateTime.UtcNow.Ticks;
                SendConnectRequest();
            }
            else
            {
                _connectId       = connectId;
                _connectionState = ConnectionState.Connected;
                SendConnectAccept();
            }

            NetUtils.DebugWrite(ConsoleColor.Cyan, "[CC] ConnectId: {0}", _connectId);
        }