Esempio n. 1
0
        public ITcpSession Pop()
        {
            ITcpSession session;

            if (!pool.TryDequeue(out session))
            {
                if (Interlocked.Increment(ref count) <= TcpServer.Config.MaxConnections)
                {
                    session                        = new TcpSession();
                    session.SessionId              = sessionId.NewId();
                    session.Pool                   = this;
                    session.ReceiveBuffer          = new byte[TcpServer.Config.BufferSize];
                    session.PacketProtocol         = TcpServer.GetProtocol();
                    session.PacketProtocol.Session = session;
                }
                else
                {
                    TcpServer.Loger.Warning("session count attain maxnum");
                }
            }
            if (session != null)
            {
                activeDict.TryAdd(session.SessionId, session);
                session.ConnectDateTime = DateTime.Now;
                session.ActiveDateTime  = DateTime.Now;
            }
            return(session);
        }
Esempio n. 2
0
        public Connect GetConnect()
        {
            var connect = new Connect(Config);

            connect.SessionId = sessionId.NewId();
            connect.Connect();
            connect.RpcContainer = rpcContainer;
            return(connect);
        }
Esempio n. 3
0
        public ITcpClientSession Pop()
        {
            ITcpClientSession session;

            if (!pool.TryDequeue(out session))
            {
                if (Interlocked.Increment(ref count) <= maxSessions)
                {
                    session                = new TcpClientSession(remoteEndPoint, bufferSize, loger);
                    session.Pool           = this;
                    session.SessionId      = sessionId.NewId();
                    session.PacketProtocol = GetProtocal();
                }
            }
            if (session != null)
            {
                activeDict.TryAdd(session.SessionId, session);
            }
            return(session);
        }
Esempio n. 4
0
        public IRUdpSession Pop()
        {
            IRUdpSession session;

            if (!pool.TryDequeue(out session))
            {
                if (Interlocked.Increment(ref count) <= RUdpServer.Config.MaxConnections)
                {
                    session                        = new RUdpSession();
                    session.SessionId              = sessionId.NewId();
                    session.Pool                   = this;
                    session.PacketProtocol         = RUdpServer.GetProtocol();
                    session.PacketProtocol.Session = session;
                }
                else
                {
                    RUdpServer.Loger.Warning("session count attain maxnum");
                }
            }
            return(session);
        }