protected virtual void OnReceiveWebSocketData(HttpRequest request, DataFrame data)
        {
            WebSocketToken token = (WebSocketToken)request.Session.Tag;

            if (data.Type == DataPacketType.ping)
            {
                DataFrame pong = CreateDataFrame();
                pong.Type = DataPacketType.pong;
                pong.FIN  = true;
                request.Session.Send(pong);
            }
            else if (data.Type == DataPacketType.connectionClose)
            {
                request.Session.Dispose();
            }
            else
            {
                var args = new WebSocketReceiveArgs();
                args.Frame   = data;
                args.Sesson  = request.Session;
                args.Server  = this;
                args.Request = request;
                WebSocketReceive?.Invoke(this, args);
            }
        }
        protected virtual void OnReceiveWebSocketData(ISession session, DataFrame data)
        {
            HttpToken token = (HttpToken)session.Tag;

            if (data.Type == DataPacketType.ping)
            {
                DataFrame pong = CreateDataFrame();
                pong.Type = DataPacketType.pong;
                pong.FIN  = true;
                session.Send(pong);
            }
            else if (data.Type == DataPacketType.connectionClose)
            {
                session.Dispose();
            }
            else
            {
                if (WebSocketReceive == null)
                {
                    ActionResult result = ExecuteWS(token.WebSocketRequest, data);
                }
                else
                {
                    var args = new WebSocketReceiveArgs();
                    args.Frame   = data;
                    args.Sesson  = session;
                    args.Server  = this;
                    args.Request = token.WebSocketRequest;
                    WebSocketReceive?.Invoke(this, args);
                }
            }
        }
        protected virtual void OnWebSocketRequest(ISession session, DataFrame data)
        {
            if (session.Count > Options.WebSocketMaxRPS)
            {
                if (EnableLog(LogType.Error))
                {
                    mServer.Log(LogType.Error, session, $"{session.RemoteEndPoint} Session message queuing exceeds maximum rps!");
                }
                session.Dispose();
                return;
            }

            if (EnableLog(LogType.Info))
            {
                mServer.Log(LogType.Info, session, "{0} receive websocket data {1}", session.RemoteEndPoint, data.Type.ToString());
            }
            HttpToken token = (HttpToken)session.Tag;

            if (data.Type == DataPacketType.ping)
            {
                DataFrame pong = CreateDataFrame();
                pong.Type = DataPacketType.pong;
                pong.FIN  = true;
                session.Send(pong);
            }
            else if (data.Type == DataPacketType.connectionClose)
            {
                session.Dispose();
            }
            else
            {
                if (WebSocketReceive == null)
                {
                    if (data.Type == DataPacketType.text)
                    {
                        ActionResult result = ExecuteWS(token.Request, data);
                    }
                }
                else
                {
                    RequestExecting();
                    try
                    {
                        var args = new WebSocketReceiveArgs();
                        args.Frame   = data;
                        args.Sesson  = session;
                        args.Server  = this;
                        args.Request = token.Request;
                        WebSocketReceive?.Invoke(this, args);
                    }
                    finally
                    {
                        RequestExecuted();
                    }
                }
            }
        }
Exemple #4
0
 protected virtual void OnWebSocketRequest(ISession session, DataFrame data)
 {
     System.Threading.Interlocked.Increment(ref mCurrentWebSocketRequests);
     try
     {
         if (EnableLog(LogType.Info))
         {
             mServer.Log(LogType.Info, session, "{0} receive websocket data {1}", session.RemoteEndPoint, data.Type.ToString());
         }
         HttpToken token = (HttpToken)session.Tag;
         if (data.Type == DataPacketType.ping)
         {
             DataFrame pong = CreateDataFrame();
             pong.Type = DataPacketType.pong;
             pong.FIN  = true;
             session.Send(pong);
         }
         else if (data.Type == DataPacketType.connectionClose)
         {
             session.Dispose();
         }
         else
         {
             if (WebSocketReceive == null)
             {
                 if (data.Type == DataPacketType.text)
                 {
                     ActionResult result = ExecuteWS(token.Request, data);
                 }
             }
             else
             {
                 var args = new WebSocketReceiveArgs();
                 args.Frame   = data;
                 args.Sesson  = session;
                 args.Server  = this;
                 args.Request = token.Request;
                 WebSocketReceive?.Invoke(this, args);
             }
         }
     }
     finally
     {
         System.Threading.Interlocked.Decrement(ref mCurrentWebSocketRequests);
     }
 }