ClientWebSocket.ConnectAsync(Uri, CancellationToken) ClientWebSocket.ConnectAsync(Uri, CancellationToken) ClientWebSocket.ConnectAsync(Uri, CancellationToken) Method

Definition

Connect to a WebSocket server as an asynchronous operation.

public:
 System::Threading::Tasks::Task ^ ConnectAsync(Uri ^ uri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ConnectAsync (Uri uri, System.Threading.CancellationToken cancellationToken);
member this.ConnectAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task

Parameters

uri
Uri Uri Uri

The URI of the WebSocket server to connect to.

cancellationToken
CancellationToken CancellationToken CancellationToken

A cancellation token used to propagate notification that the operation should be canceled.

Returns

The task object representing the asynchronous operation.

Remarks

The ConnectAsync method initiates the WebSocket handshake with a remote network destination, and then negotiates the sub-protocol.

For plain WebSocket connections, use the ws:// scheme in the uri. For secure WebSocket connections over TLS/SSL, use the wss:// scheme.

This operation will not block. The returned Task object will complete after the connect request on the ClientWebSocket instance has completed.

Applies to