Пример #1
0
        /*
         * public string ToJSONString()
         * {
         *  return JsonConvert.SerializeObject(this);
         * }
         */

        public static SignedMessage FromJSONString(string jsonString)
        {
            SignedMessage message = JsonConvert.DeserializeObject <SignedMessage>(jsonString);

            return(message);
        }
Пример #2
0
        private async Task Receive(ClientWebSocket socket)
        {
            var buffer = new ArraySegment <byte>(new byte[2048]);

            do
            {
                WebSocketReceiveResult result;
                using (var ms = new MemoryStream())
                {
                    do
                    {
                        result = await socket.ReceiveAsync(buffer, CancellationToken.None);

                        ms.Write(buffer.Array, buffer.Offset, result.Count);
                    } while (!result.EndOfMessage);

                    if (result.MessageType == WebSocketMessageType.Close)
                    {
                        break;
                    }

                    ms.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(ms)) MessageReceived(MyRSA.VerifyAndDecrypt(SignedMessage.FromJSONString(await reader.ReadToEndAsync())));
                }
            } while (true);
        }