Exemplo n.º 1
0
        public async override Task ReceiveMessage(string sessionKey, WebsocketSessionPeer peer, WebSocketReceiveResult result, byte[] buffer)
        {
            WebsocketSessionError error = new WebsocketSessionError {
                ErrorCode = "WP_001", Message = "Progress Sessions do not expect messages from the client."
            };

            SendMessage(peer.Socket, error);
        }
        // access the websocket data as a string; (if you JSON serialized, you might want to only override this function
        // because you'll know that all of your data will be a string that you are going to deserialize;
        // If you wanted to do something like streaming video via direct byte arrays, you'd want to override the other
        // "receive" function.
        public virtual async Task ReceiveMessageString(string sessionKey, WebsocketSessionPeer peer, WebSocketReceiveResult result, string socketMessage)
        {
            try
            {
                // parse the request to access the data;
                WebsocketSessionMessageRequest messageRequest = System.Text.Json.JsonSerializer.Deserialize <WebsocketSessionMessageRequest>(socketMessage);
                if (messageRequest.Type == WebsocketSessionMessageType.Unknown)
                {
                    messageRequest.Type = WebsocketSessionMessageType.Text;
                }

                // process the request and send the response message, if applicable;
                ProcessMessageRequest(messageRequest, sessionKey, peer);
            }
            catch (Exception exception)
            {
                WebsocketSessionError error = new WebsocketSessionError()
                {
                    ErrorCode = "WP_002", Message = "An error occurred while processing the message"
                };
                SendMessage(peer.Socket, error);
            }
        }