WebSocket.ReceiveAsync Method (ArraySegment<Byte>, CancellationToken)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Receives data from the WebSocket connection asynchronously.

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

public abstract Task<WebSocketReceiveResult> ReceiveAsync(
	ArraySegment<byte> buffer,
	CancellationToken cancellationToken


Type: System.ArraySegment<Byte>

References the application buffer that is the storage location for the received data.

Type: System.Threading.CancellationToken

Propagates the notification that operations should be canceled.

Return Value

Type: System.Threading.Tasks.Task<WebSocketReceiveResult>

Returns Task<TResult>.

The task object representing the asynchronous operation. The Result property on the task object returns a Byte array containing the received data.

This operation will not block. The returned Task<TResult> object will complete after the data has been received on the WebSocket.

Exactly one send and one receive is supported on each WebSocket object in parallel.

.NET Framework
Available since 4.5
Return to top