System.Net.WebSockets.ClientWebSocket.ConnectAsync Method

Connect to a WebSocket server as an asynchronous operation.

Syntax

[System.Diagnostics.DebuggerStepThrough]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(System.Net.WebSockets.ClientWebSocket/<ConnectAsync>c__async0))]
public System.Threading.Tasks.Task ConnectAsync (Uri uri, System.Threading.CancellationToken cancellationToken)

Parameters

uri
The URI of the WebSocket server to connect to.
cancellationToken
A cancellation token used to propagate notification that the operation should be canceled.

Returns

Returns System.Threading.Tasks.Task.

The task object representing the asynchronous operation.

Remarks

The ClientWebSocket.ConnectAsync(Uri, System.Threading.CancellationToken) 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 System.Threading.Tasks.Task object will complete after the connect request on the System.Net.WebSockets.ClientWebSocket instance has completed.

Requirements

Namespace: System.Net.WebSockets
Assembly: System (in System.dll)
Assembly Versions: 4.0.0.0