예제 #1
0
        internal NetPeer(NetManager peerListener, NetEndPoint remoteEndPoint, long connectId)
        {
            _packetPool     = peerListener.PacketPool;
            _peerListener   = peerListener;
            _remoteEndPoint = remoteEndPoint;

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

            _reliableOrderedChannel   = new ReliableChannel(this, true, _windowSize);
            _reliableUnorderedChannel = new ReliableChannel(this, false, _windowSize);
            _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);
        }
예제 #2
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;
        }