void ProcessPackageWithoutSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, byte[] receivedData)
        {
            var sessionID = remoteEndPoint.ToString();
            var appSession = AppServer.GetAppSessionByID(sessionID);

            if (appSession == null) //New session
            {
                if (!DetectConnectionNumber(remoteEndPoint))
                    return;

                var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);

                appSession = AppServer.CreateAppSession(socketSession);

                if (appSession == null)
                    return;

                Interlocked.Increment(ref m_ConnectionCount);
                socketSession.Closed += OnSocketSessionClosed;
                socketSession.Start();

                appSession.ProcessRequest(receivedData, 0, receivedData.Length, false);
            }
            else //Existing session
            {
                appSession.ProcessRequest(receivedData, 0, receivedData.Length, false);
            }
        }
示例#2
0
        IAppSession CreateNewSession(Socket listenSocket, IPEndPoint remoteEndPoint, string sessionID)
        {
            if (!DetectConnectionNumber(remoteEndPoint))
            {
                return(null);
            }

            var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);
            var appSession    = AppServer.CreateAppSession(socketSession);

            if (appSession == null)
            {
                return(null);
            }

            if (!DetectConnectionNumber(remoteEndPoint))
            {
                return(null);
            }

            if (!AppServer.RegisterSession(appSession))
            {
                return(null);
            }

            Interlocked.Increment(ref m_ConnectionCount);

            socketSession.Closed += OnSocketSessionClosed;
            socketSession.Start();

            return(appSession);
        }
示例#3
0
        protected UdpSocketSession <TAppSession, TCommandInfo> RegisterSession(UdpSocketSession <TAppSession, TCommandInfo> socketSession)
        {
            TAppSession appSession = this.AppServer.CreateAppSession(socketSession);

            if (appSession == null)
            {
                return(null);
            }

            socketSession.Initialize(this.AppServer, appSession);
            return(socketSession);
        }
示例#4
0
        void ProcessPackageWithoutSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, ArraySegment <byte> receivedData)
        {
            var sessionID  = remoteEndPoint.ToString();
            var appSession = AppServer.GetSessionByID(sessionID);

            if (appSession == null) //New session
            {
                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);

                appSession = AppServer.CreateAppSession(socketSession);

                if (appSession == null)
                {
                    return;
                }

                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                if (!AppServer.RegisterSession(appSession))
                {
                    return;
                }

                Interlocked.Increment(ref m_ConnectionCount);
                socketSession.Closed += OnSocketSessionClosed;
                socketSession.Start();
            }

            ((UdpSocketSession)appSession.SocketSession).ProcessReceivedData(receivedData, null);
        }
示例#5
0
        void ProcessPackageWithSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, ArraySegment <byte> receivedData)
        {
            TPackageInfo requestInfo;

            string sessionID;

            int rest;

            try
            {
                var receiveData = new BufferList();
                receiveData.Add(receivedData);

                requestInfo = this.m_UdpRequestFilter.Filter(receiveData, out rest);
            }
            catch (Exception exc)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Failed to parse UDP package!", exc);
                }
                return;
            }

            var udpRequestInfo = requestInfo as IUdpPackageInfo;

            if (rest > 0)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("The output parameter rest must be zero in this case!");
                }
                return;
            }

            if (udpRequestInfo == null)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Invalid UDP package format!");
                }
                return;
            }

            if (string.IsNullOrEmpty(udpRequestInfo.SessionID))
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Failed to get session key from UDP package!");
                }
                return;
            }

            sessionID = udpRequestInfo.SessionID;

            var appSession = AppServer.GetSessionByID(sessionID);

            if (appSession == null)
            {
                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);
                appSession = AppServer.CreateAppSession(socketSession);

                if (appSession == null)
                {
                    return;
                }

                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                if (!AppServer.RegisterSession(appSession))
                {
                    return;
                }

                Interlocked.Increment(ref m_ConnectionCount);

                socketSession.Closed += OnSocketSessionClosed;
                socketSession.Start();
            }
            else
            {
                var socketSession = appSession.SocketSession as UdpSocketSession;
                //Client remote endpoint may change, so update session to ensure the server can find client correctly
                socketSession.UpdateRemoteEndPoint(remoteEndPoint);
            }

            m_RequestHandler.ExecuteCommand(appSession, requestInfo);
        }