Export (0) Print
Expand All

ClientWebSocket.ConnectAsync Method

.NET Framework 4.5

Connect to a WebSocket server as an asynchronous operation.

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

public Task ConnectAsync(
	Uri uri,
	CancellationToken cancellationToken


Type: System.Uri

The URI of the WebSocket server to connect to.

Type: System.Threading.CancellationToken

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

Return Value

Type: System.Threading.Tasks.Task
Returns Task.
The task object representing the asynchronous operation.

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.

.NET Framework

Supported in: 4.6, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft