예제 #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
 //for low memory consumption
 private void Initialize()
 {
     _reliableOrderedChannel   = new ReliableChannel(this, true);
     _reliableUnorderedChannel = new ReliableChannel(this, false);
     _sequencedChannel         = new SequencedChannel(this, false);
     _unreliableChannel        = new SimpleChannel(this);
     _reliableSequencedChannel = new SequencedChannel(this, true);
     _holdedFragments          = new Dictionary <ushort, IncomingFragments>();
 }
예제 #3
0
 //for low memory consumption
 private void Initialize()
 {
     _reliableOrderedChannel   = new ReliableChannel(this, true);
     _reliableUnorderedChannel = new ReliableChannel(this, false);
     _sequencedChannel         = new SequencedChannel(this, false);
     _unreliableChannel        = new SimpleChannel(this);
     _reliableSequencedChannel = new SequencedChannel(this, true);
     _holdedFragments          = new Dictionary <ushort, IncomingFragments>();
     _mergeData  = new NetPacket(PacketProperty.Merged, NetConstants.MaxPacketSize);
     _pongPacket = new NetPacket(PacketProperty.Pong, 0);
     _pingPacket = new NetPacket(PacketProperty.Ping, 0);
 }
예제 #4
0
        internal NetPeer(NetBase peerListener, NetEndPoint remoteEndPoint)
        {
            _peerListener   = peerListener;
            _id             = remoteEndPoint.GetId();
            _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);

            _packetPool      = new Stack <NetPacket>();
            _holdedFragments = new Dictionary <ushort, IncomingFragments>();
        }
예제 #5
0
 //incoming connection constructor
 internal NetPeer(NetManager netManager, IPEndPoint remoteEndPoint, int id)
 {
     Id                        = id;
     Statistics                = new NetStatistics();
     _packetPool               = netManager.NetPacketPool;
     _netManager               = netManager;
     _remoteEndPoint           = remoteEndPoint;
     _connectionState          = ConnectionState.Incoming;
     _mergeData                = new NetPacket(PacketProperty.Merged, NetConstants.MaxPacketSize);
     _pongPacket               = new NetPacket(PacketProperty.Pong, 0);
     _pingPacket               = new NetPacket(PacketProperty.Ping, 0);
     _reliableOrderedChannel   = new ReliableChannel(this, true);
     _reliableUnorderedChannel = new ReliableChannel(this, false);
     _sequencedChannel         = new SequencedChannel(this, false);
     _unreliableChannel        = new SimpleChannel(this);
     _reliableSequencedChannel = new SequencedChannel(this, true);
     _holdedFragments          = new Dictionary <ushort, IncomingFragments>();
 }
예제 #6
0
파일: NetPeer.cs 프로젝트: ayuexs/C-
        //incoming connection constructor
        internal NetPeer(NetManager netManager, IPEndPoint remoteEndPoint, int id)
        {
            Id               = id;
            Statistics       = new NetStatistics();
            _packetPool      = netManager.NetPacketPool;
            _netManager      = netManager;
            _remoteEndPoint  = remoteEndPoint;
            _connectionState = ConnectionState.Incoming;
            _mergeData       = new NetPacket(PacketProperty.Merged, NetConstants.MaxPacketSize);
            _pongPacket      = new NetPacket(PacketProperty.Pong, 0);
            _pingPacket      = new NetPacket(PacketProperty.Ping, 0)
            {
                Sequence = 1
            };

            _unreliableChannel = new SimpleChannel(this);
            _headChannel       = _unreliableChannel;
            _holdedFragments   = new Dictionary <ushort, IncomingFragments>();

            _channels = new BaseChannel[netManager.ChannelsCount * 4];
        }
예제 #7
0
        private NetPeer(NetManager netManager, NetEndPoint 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);
            _simpleChannel            = new SimpleChannel(this);
            _reliableSequencedChannel = new ReliableSequencedChannel(this);

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

            _mergeData = _packetPool.Get(PacketProperty.Merged, NetConstants.MaxPacketSize);
        }
예제 #8
0
        private NetPeer(NetManager netManager, NetEndPoint remoteEndPoint)
        {
            Statistics      = new NetStatistics();
            _packetPool     = netManager.NetPacketPool;
            _netManager     = netManager;
            _remoteEndPoint = remoteEndPoint;

            if (netManager.MtuStartIdx >= 0 && netManager.MtuStartIdx < NetConstants.PossibleMtu.Length)
            {
                _mtuIdx    = netManager.MtuStartIdx;
                _mtu       = NetConstants.PossibleMtu[_mtuIdx];
                _finishMtu = true;
            }

            _avgRtt        = 0;
            _rtt           = 0;
            _pingSendTimer = 0;
            _pingMustSend  = false;

            if (NetManager.EnableReliableOrderedChannel)
            {
                _reliableOrderedChannels = new ReliableChannel[NetConstants.MultiChannelCount];
            }
            if (NetManager.EnableReliableUnorderedChannel)
            {
                _reliableUnorderedChannels = new ReliableChannel[NetConstants.MultiChannelCount];
            }
            if (NetManager.EnableSequencedChannel)
            {
                _sequencedChannels = new SequencedChannel[NetConstants.MultiChannelCount];
            }
            if (NetManager.EnableSimpleChannel)
            {
                _simpleChannels = new SimpleChannel[NetConstants.MultiChannelCount];
            }
            //_reliableSequencedChannels = new ReliableSequencedChannel[NetConstants.MultiChannelCount];

            // Initialise default channel
            for (int i = 0; i < NetConstants.MultiChannelCount; ++i)
            {
                if (NetManager.EnableReliableOrderedChannel)
                {
                    _reliableOrderedChannels[i] = new ReliableChannel(this, true, i);
                }
                if (NetManager.EnableReliableUnorderedChannel)
                {
                    _reliableUnorderedChannels[i] = new ReliableChannel(this, false, i);
                }
                if (NetManager.EnableSequencedChannel)
                {
                    _sequencedChannels[i] = new SequencedChannel(this, i);
                }
                if (NetManager.EnableSimpleChannel)
                {
                    _simpleChannels[i] = new SimpleChannel(this, i);
                }
                //_reliableSequencedChannels[i] = new ReliableSequencedChannel(this, i);
            }

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

            _mergeData = _packetPool.Get(PacketProperty.Merged, 0, NetConstants.MaxPacketSize);
        }
예제 #9
0
        internal NetPeer(NetBase peerListener, NetEndPoint remoteEndPoint)
        {
            _peerListener = peerListener;
            _id = remoteEndPoint.GetId();
            _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);

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

            _mergeData.Init(PacketProperty.Merged, NetConstants.PossibleMtu[NetConstants.PossibleMtu.Length - 1]);
        }