Example #1
0
        public ServerSession(SessionCreateInfo createInfo)
        {
            SessionId   = createInfo.SessionId;
            _tcpChannel = createInfo.TcpChannel;
            if (_tcpChannel != null)
            {
                _tcpChannel.PacketReceived = OnReceiveFromChannel;
            }

            _udpChannel = createInfo.UdpChannel;
            if (_udpChannel != null)
            {
                _udpChannel.PacketReceived = OnReceiveFromChannel;
            }

            _request = new SessionRequest(this, createInfo.Statistic);
        }
Example #2
0
        public DefaultSessionFactory(
            ServerOption serverOption,
            ILoggerFactory loggerFactory,
            NetStatistic statistic,
            Func <SessionCreateInfo, ServerSession> createSessionFunc = null)
        {
            createSessionFunc = createSessionFunc ?? CreateSession;

            _sessionQueue = new ConcurrentQueue <ISession>();
            _maxSession   = serverOption.MaxSession;

            var createInfo = new SessionCreateInfo();

            for (int i = 0; i < _maxSession; ++i)
            {
                TcpChannel tcpChannel = new TcpChannel(
                    serverOption,
                    loggerFactory.CreateLogger(nameof(TcpChannel)),
                    statistic);

                UdpChannel udpChannel = null;

                if (serverOption.IsServiceUdp)
                {
                    udpChannel = new UdpChannel(
                        serverOption,
                        loggerFactory.CreateLogger(nameof(UdpChannel)),
                        statistic,
                        0);
                }

                createInfo.SessionId  = (ushort)(i + 1);
                createInfo.TcpChannel = tcpChannel;
                createInfo.UdpChannel = udpChannel;
                createInfo.Statistic  = statistic;

                ServerSession session = createSessionFunc(createInfo);

                _sessionQueue.Enqueue(session);
            }
        }
Example #3
0
 private ServerSession CreateSession(SessionCreateInfo createInfo)
 {
     return(new ServerSession(createInfo));
 }
Example #4
0
 public UserSession(SessionCreateInfo createInfo)
     : base(createInfo)
 {
 }