AspNetWebSocket.CloseOutputAsync Method (WebSocketCloseStatus, String, CancellationToken)

.NET Framework (current version)
 

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.

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

public override Task CloseOutputAsync(
	WebSocketCloseStatus closeStatus,
	string statusDescription,
	CancellationToken cancellationToken
)

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.

Return Value

Type: System.Threading.Tasks.Task

A reference to the operation.

Exception Condition
ObjectDisposedException

The object was previously disposed.

System.InvalidOperationException

The AspNetWebSocket object is in an aborted state.

-or-

Sending operations are unavailable.

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.

.NET Framework
Available since 4.5
Return to top
Show: