AspNetWebSocket.CloseOutputAsync Method (WebSocketCloseStatus, String, CancellationToken)
Sends an asynchronous message to a client to close the connection. If the server initiates the request to close the connection, the method returns without waiting for a response.
Assembly: System.Web (in System.Web.dll)
override CloseOutputAsync : closeStatus:WebSocketCloseStatus * statusDescription:string * cancellationToken:CancellationToken -> Task
Parameters
- closeStatus
-
Type:
System.Net.WebSockets.WebSocketCloseStatus
The status code of the close operation.
- statusDescription
-
Type:
System.String
The status message of the close operation.
- cancellationToken
-
Type:
System.Threading.CancellationToken
The object that cancels a pending operation.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The object was previously disposed. |
| System.InvalidOperationException |
You can use the CloseAsync and CloseOutputAsync methods for both client-initiated and server-initiated requests to close an AspNetWebSocket connection. The two methods handle client-initiated requests in the same way: After the client sends a message to the server to close the connection, the server calls one of these methods and sends an acknowledgment to the client, and then the method returns.
For server-initiated requests, the two methods work differently. The CloseAsync method sends a message to the client to close the connection, waits for a response, and then returns. The server does not wait for any additional data sent by the client. In contrast, the CloseOutputAsync method sends a message to the client to close the connection and returns without waiting for a response. After the method returns, you can call the ReceiveAsync method and handle either additional data or the acknowledgment that the client sends.
Available since 4.5