예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 protected string GetReceiveQueryString(IConnection connection, string data)
 {
     return(TransportHelper.GetReceiveQueryString(connection, data, _transport));
 }