Exemplo n.º 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);

            base.TrySetResult(s);
        }
        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);

            if (Decoder != null)
            {
                s = Decoder.DecodeCommand(s);
            }

            var response = LXResponse <T> .Deserialize(s);

            base.TrySetResult(response);
        }
Exemplo n.º 3
0
        private async Task OpenWebSocketAsync(CancellationToken cancellationToken)
        {
            var uri = new UriBuilder(_baseUri);

            uri.Scheme = HttpUtils.WebSocketScheme;

            var credentials = _credentials.GetCredential(uri.Uri, HttpUtils.BasicAuthenticationScheme);

            if (credentials == null)
            {
                throw new InvalidOperationException();
            }

            _webSocket = new Transport.LXWebSocket(uri.Uri, credentials);
            await _webSocket.OpenAsync(cancellationToken).ConfigureAwait(false);

            StartKeepAliveTimer();
        }
Exemplo n.º 4
0
 public abstract Task HandleMessageAsync(MessageHeader header, LXWebSocket socket, CancellationToken cancellationToken);