コード例 #1
0
        public override async Task HandleMessageAsync(MessageHeader header, LXWebSocket socket, CancellationToken cancellationToken)
        {
            var content = new byte[header.Length];
            await socket.ReceiveAtomicAsync(new ArraySegment <byte>(content), true, cancellationToken).ConfigureAwait(false);

            var s        = LXWebSocket.Encoding.GetString(content);
            var response = LXResponse <T> .Deserialize(s);

            base.TrySetResult(response);
        }
コード例 #2
0
        protected override async Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken)
        {
            EnsureHttpClient();
            using var response = await _httpClient.GetAsync(command, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

            if (response.IsSuccessStatusCode && HttpUtils.IsJsonMediaType(response.Content.Headers.ContentType))
            {
                string contentStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var lxResponse = LXResponse <T> .Deserialize(contentStr);

                return(lxResponse);
            }
            else
            {
                throw new MiniserverTransportException();
            }
        }