public Task ConnectAsync() { Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters); _client = new WebsocketClient(wsUri); _client.MessageReceived.Subscribe(Listen); _client.DisconnectionHappened.Subscribe(info => { if (info.Type != DisconnectionType.ByUser) { CloseHandler(); } }); var token = new CancellationTokenSource(ConnectTimeout).Token; token.ThrowIfCancellationRequested(); try { _client.Start().Wait(token); } catch (Exception e) { if (e is OperationCanceledException) { throw new TimeoutException(); } throw e; } return(Task.CompletedTask); }
public async Task ConnectAsync() { Uri wsUri = UrlConverter.HttpToWs(ServerUri, _options); await Socket.ConnectAsync(wsUri, new WebSocketConnectionOptions { ConnectionTimeout = _options.ConnectionTimeout }); }
public async Task ConnectAsync() { _tokenSource = new CancellationTokenSource(); Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); await _socket.ConnectAsync(wsUri, CancellationToken.None); Listen(); }
public Task ConnectAsync() { _tokenSource = new CancellationTokenSource(); Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); bool executed = _socket.ConnectAsync(wsUri, CancellationToken.None).Wait(ConnectTimeout); if (!executed) { throw new TimeoutException(); } Listen(); return(Task.CompletedTask); }