Example #1
0
        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);
            }
        }
Example #2
0
        protected virtual void OnWebSocketConnect(HttpRequest request, HttpResponse response)
        {
            response.ConnectionUpgradeWebsocket(request.Header[HeaderType.SEC_WEBSOCKET_KEY]);
            request.Session.Send(response);
            WebSocketToken token = (WebSocketToken)request.Session.Tag;

            token.Connected = true;
        }
Example #3
0
        public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e)
        {
            WebSocketToken token   = (WebSocketToken)e.Session.Tag;
            HttpRequest    request = e.Message as HttpRequest;

            if (request != null)
            {
                token.ConnectionRequest = request;
                OnWebSocketConnect(request, request.CreateResponse());
            }
            else
            {
                OnReceiveWebSocketData(token.ConnectionRequest, (DataFrame)e.Message);
            }
        }