ClientWebSocket.ConnectAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ConnectAsync(Uri, CancellationToken) |
Connects to a WebSocket server as an asynchronous operation. |
ConnectAsync(Uri, HttpMessageInvoker, CancellationToken) |
Connects to a WebSocket server as an asynchronous operation. |
ConnectAsync(Uri, CancellationToken)
- Source:
- ClientWebSocket.cs
- Source:
- ClientWebSocket.cs
- Source:
- ClientWebSocket.cs
Connects 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
Public Function ConnectAsync (uri As Uri, cancellationToken As CancellationToken) As Task
Parameters
- uri
- Uri
The URI of the WebSocket server to connect to.
- cancellationToken
- CancellationToken
A cancellation token used to propagate notification that the operation should be canceled.
Returns
The task object representing the asynchronous operation.
Exceptions
The cancellation token was canceled. This exception is stored into the returned task.
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.
The WebSocket handshake request has default headers for HTTP/1.1 request:
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Key: [generated key]
For HTTP/2 request:
:protocol: websocket
By default, HTTP/1.1 will be used. To change HTTP version used or enable HTTP version upgrade/downgrade, see HttpVersion option and HttpVersionPolicy option.
Applies to
ConnectAsync(Uri, HttpMessageInvoker, CancellationToken)
- Source:
- ClientWebSocket.cs
- Source:
- ClientWebSocket.cs
- Source:
- ClientWebSocket.cs
Connects to a WebSocket server as an asynchronous operation.
public:
System::Threading::Tasks::Task ^ ConnectAsync(Uri ^ uri, System::Net::Http::HttpMessageInvoker ^ invoker, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ConnectAsync (Uri uri, System.Net.Http.HttpMessageInvoker? invoker, System.Threading.CancellationToken cancellationToken);
member this.ConnectAsync : Uri * System.Net.Http.HttpMessageInvoker * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ConnectAsync (uri As Uri, invoker As HttpMessageInvoker, cancellationToken As CancellationToken) As Task
Parameters
- uri
- Uri
The URI of the WebSocket server to connect to.
- invoker
- HttpMessageInvoker
The HttpMessageInvoker instance to use for connecting.
- cancellationToken
- CancellationToken
A cancellation token used to propagate notification that the operation should be canceled.
Returns
The task object representing the asynchronous operation.
Exceptions
The cancellation token was canceled. This exception is stored into the returned task.