示例#1
0
        public LidgrenNatPunchClient(ICoroutineScheduler coroutineScheduler, LidgrenNatFacilitatorConnection facilitatorConnection,
                                     IConnectionlessTransporter transporter)
        {
            _tempBuffer            = new NetBuffer();
            _transporter           = transporter;
            _facilitatorConnection = facilitatorConnection;

            _natPunchAttempts      = new Dictionary <NatPunchId, PunchAttempt>();
            _natPunchRegistrations = new List <PunchAttempt>();
//            _natPunchSessionCache = new RamjetCache<IPEndPoint, IPEndPoint>(
//                expireAfterAccess: _punchSessionCacheTimeout, expireAfterWrite: null);

            _facilitatorConnection.OnNatPunchSuccess += OnNatPunchSuccess;
            _facilitatorConnection.OnNatPunchFailure += OnNatPunchFailure;
            _cleanupRoutine = coroutineScheduler.Run(ConnectionTimeoutCleanup());
        }
        public LidgrenNatPunchClient(ICoroutineScheduler coroutineScheduler, LidgrenNatFacilitatorConnection facilitatorConnection)
        {
            _facilitatorConnection = facilitatorConnection;

            _punchAttemptPool = new ObjectPool <PunchAttempt>(() => new PunchAttempt());

            {
                const int natpunchIdCount = 256;
                var       punchIds        = new NatPunchId[natpunchIdCount];
                for (int i = 0; i < natpunchIdCount; i++)
                {
                    punchIds[i] = new NatPunchId(Guid.NewGuid().ToString());
                }
                _natPunchIds = CollectionUtil.LoopingEnumerator(punchIds);
            }

            _natPunchAttempts      = new Dictionary <NatPunchId, IPooledObject <PunchAttempt> >();
            _natPunchRegistrations = new List <IPooledObject <PunchAttempt> >();
            _facilitatorConnection.OnNatPunchSuccess += OnNatPunchSuccess;
            _facilitatorConnection.OnNatPunchFailure += OnNatPunchFailure;
            _cleanupRoutine = coroutineScheduler.Run(ConnectionTimeoutCleanup());
        }