HttpListenerContext.AcceptWebSocketAsync Method

Definition

Accept a WebSocket connection as an asynchronous operation.

Overloads

AcceptWebSocketAsync(String)

Accept a WebSocket connection as an asynchronous operation.

AcceptWebSocketAsync(String, TimeSpan)

Accept a WebSocket connection specifying the supported WebSocket sub-protocol and WebSocket keep-alive interval as an asynchronous operation.

AcceptWebSocketAsync(String, Int32, TimeSpan)

Accept a WebSocket connection specifying the supported WebSocket sub-protocol, receive buffer size, and WebSocket keep-alive interval as an asynchronous operation.

AcceptWebSocketAsync(String, Int32, TimeSpan, ArraySegment<Byte>)

Accept a WebSocket connection specifying the supported WebSocket sub-protocol, receive buffer size, WebSocket keep-alive interval, and the internal buffer as an asynchronous operation.

AcceptWebSocketAsync(String)

Source:
HttpListenerContext.cs
Source:
HttpListenerContext.cs
Source:
HttpListenerContext.cs

Accept a WebSocket connection as an asynchronous operation.

C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol);
C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol);

Parameters

subProtocol
String

The supported WebSocket sub-protocol.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an HttpListenerWebSocketContext object.

Exceptions

subProtocol is an empty string

-or-

subProtocol contains illegal characters.

An error occurred when sending the response to complete the WebSocket handshake.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

The size of the receive buffer is 16,385 bytes. The WebSocket keep-alive interval is set to the default value of 30,000 (30 seconds).

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AcceptWebSocketAsync(String, TimeSpan)

Source:
HttpListenerContext.cs
Source:
HttpListenerContext.cs
Source:
HttpListenerContext.cs

Accept a WebSocket connection specifying the supported WebSocket sub-protocol and WebSocket keep-alive interval as an asynchronous operation.

C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, TimeSpan keepAliveInterval);
C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, TimeSpan keepAliveInterval);

Parameters

subProtocol
String

The supported WebSocket sub-protocol.

keepAliveInterval
TimeSpan

The WebSocket protocol keep-alive interval in milliseconds.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an HttpListenerWebSocketContext object.

Exceptions

subProtocol is an empty string

-or-

subProtocol contains illegal characters.

keepAliveInterval is too small.

An error occurred when sending the response to complete the WebSocket handshake.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

The size of the receive buffer is 16,385 bytes.

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AcceptWebSocketAsync(String, Int32, TimeSpan)

Source:
HttpListenerContext.Managed.cs
Source:
HttpListenerContext.Managed.cs
Source:
HttpListenerContext.Managed.cs

Accept a WebSocket connection specifying the supported WebSocket sub-protocol, receive buffer size, and WebSocket keep-alive interval as an asynchronous operation.

C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval);
C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval);

Parameters

subProtocol
String

The supported WebSocket sub-protocol.

receiveBufferSize
Int32

The receive buffer size in bytes.

keepAliveInterval
TimeSpan

The WebSocket protocol keep-alive interval in milliseconds.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an HttpListenerWebSocketContext object.

Exceptions

subProtocol is an empty string

-or-

subProtocol contains illegal characters.

keepAliveInterval is too small.

-or-

receiveBufferSize is less than 16 bytes

-or-

receiveBufferSize is greater than 64K bytes.

An error occurred when sending the response to complete the WebSocket handshake.

Remarks

This operation will not block. The returned Task<TResult> > object will complete after the WebSocket connection has been accepted.

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AcceptWebSocketAsync(String, Int32, TimeSpan, ArraySegment<Byte>)

Source:
HttpListenerContext.Managed.cs
Source:
HttpListenerContext.Managed.cs
Source:
HttpListenerContext.Managed.cs

Accept a WebSocket connection specifying the supported WebSocket sub-protocol, receive buffer size, WebSocket keep-alive interval, and the internal buffer as an asynchronous operation.

C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer);
C#
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer);

Parameters

subProtocol
String

The supported WebSocket sub-protocol.

receiveBufferSize
Int32

The receive buffer size in bytes.

keepAliveInterval
TimeSpan

The WebSocket protocol keep-alive interval in milliseconds.

internalBuffer
ArraySegment<Byte>

An internal buffer to use for this operation.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an HttpListenerWebSocketContext object.

Exceptions

subProtocol is an empty string

-or-

subProtocol contains illegal characters.

keepAliveInterval is too small.

-or-

receiveBufferSize is less than 16 bytes

-or-

receiveBufferSize is greater than 64K bytes.

An error occurred when sending the response to complete the WebSocket handshake.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1