private async Task PerformConnect(bool reconnecting = false) { var url = _connectionInfo.Connection.Url + (reconnecting ? "reconnect" : "connect"); url += TransportHelper.GetReceiveQueryString(_connectionInfo.Connection, _connectionInfo.Data, "webSockets"); var builder = new UriBuilder(url); builder.Scheme = builder.Scheme == "https" ? "wss" : "ws"; _connectionInfo.Connection.Trace(TraceLevels.Events, "WS: {0}", builder.Uri); var webSocket = new ClientWebSocket(); _connectionInfo.Connection.PrepareRequest(new WebSocketWrapperRequest(webSocket)); await webSocket.ConnectAsync(builder.Uri, _disconnectToken); await ProcessWebSocketRequestAsync(webSocket, _disconnectToken); }
private async Task PerformConnect(bool reconnecting) { var url = _connectionInfo.Connection.Url + (reconnecting ? "reconnect" : "connect"); url += TransportHelper.GetReceiveQueryString(_connectionInfo.Connection, _connectionInfo.Data, "webSockets"); var builder = new UriBuilder(url); builder.Scheme = builder.Scheme == "https" ? "wss" : "ws"; _connectionInfo.Connection.Trace(TraceLevels.Events, "WS Connecting to: {0}", builder.Uri); // TODO: Revisit thread safety of this assignment _webSocketTokenSource = new CancellationTokenSource(); _webSocket = new ClientWebSocket(); _connectionInfo.Connection.PrepareRequest(new WebSocketWrapperRequest(_webSocket, _connectionInfo.Connection)); CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_webSocketTokenSource.Token, _disconnectToken); CancellationToken token = linkedCts.Token; await _webSocket.ConnectAsync(builder.Uri, token); await ProcessWebSocketRequestAsync(_webSocket, token); }
protected string GetReceiveQueryString(IConnection connection, string data) { return(TransportHelper.GetReceiveQueryString(connection, data, _transport)); }