HttpListenerContext.AcceptWebSocketAsync 方法

定義

以非同步作業的方式接受 WebSocket 連接。Accept a WebSocket connection as an asynchronous operation.

多載

AcceptWebSocketAsync(String)

以非同步作業的方式接受 WebSocket 連接。Accept a WebSocket connection as an asynchronous operation.

AcceptWebSocketAsync(String, TimeSpan)

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定和 WebSocket Keep-alive 間隔。Accept a WebSocket connection specifying the supported WebSocket sub-protocol and WebSocket keep-alive interval as an asynchronous operation.

AcceptWebSocketAsync(String, Int32, TimeSpan)

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定、接收緩衝區大小和 WebSocket Keep-alive 間隔。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>)

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定、接收緩衝區大小、WebSocket Keep-alive 間隔和內部緩衝區。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)

以非同步作業的方式接受 WebSocket 連接。Accept a WebSocket connection as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::WebSockets::HttpListenerWebSocketContext ^> ^ AcceptWebSocketAsync(System::String ^ subProtocol);
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync (string subProtocol);
member this.AcceptWebSocketAsync : string -> System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext>
Public Function AcceptWebSocketAsync (subProtocol As String) As Task(Of HttpListenerWebSocketContext)

參數

subProtocol
String

支援的 WebSocket 子通訊協定。The supported WebSocket sub-protocol.

傳回

代表非同步作業的工作物件。The task object representing the asynchronous operation. 工作物件上的 Result 屬性會傳回 HttpListenerWebSocketContext 物件。The Result property on the task object returns an HttpListenerWebSocketContext object.

例外狀況

subProtocol 為空字串subProtocol is an empty string -或--or- subProtocol 包含不合法的字元。subProtocol contains illegal characters.

傳送回應以完成 WebSocket 信號交換時發生錯誤。An error occurred when sending the response to complete the WebSocket handshake.

備註

這項作業不會封鎖。This operation will not block. 在接受 WebSocket 連線之後,傳回的 Task<TResult> 物件將會完成。The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

接收緩衝區的大小為16385個位元組。The size of the receive buffer is 16,385 bytes. WebSocket keep-alive 間隔設定為預設值30000(30秒)。The WebSocket keep-alive interval is set to the default value of 30,000 (30 seconds).

另請參閱

AcceptWebSocketAsync(String, TimeSpan)

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定和 WebSocket Keep-alive 間隔。Accept a WebSocket connection specifying the supported WebSocket sub-protocol and WebSocket keep-alive interval as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::WebSockets::HttpListenerWebSocketContext ^> ^ AcceptWebSocketAsync(System::String ^ subProtocol, TimeSpan keepAliveInterval);
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync (string subProtocol, TimeSpan keepAliveInterval);
member this.AcceptWebSocketAsync : string * TimeSpan -> System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext>
Public Function AcceptWebSocketAsync (subProtocol As String, keepAliveInterval As TimeSpan) As Task(Of HttpListenerWebSocketContext)

參數

subProtocol
String

支援的 WebSocket 子通訊協定。The supported WebSocket sub-protocol.

keepAliveInterval
TimeSpan

WebSocket 通訊協定保持連接間隔 (以毫秒為單位)。The WebSocket protocol keep-alive interval in milliseconds.

傳回

代表非同步作業的工作物件。The task object representing the asynchronous operation. 工作物件上的 Result 屬性會傳回 HttpListenerWebSocketContext 物件。The Result property on the task object returns an HttpListenerWebSocketContext object.

例外狀況

subProtocol 為空字串subProtocol is an empty string -或--or- subProtocol 包含不合法的字元。subProtocol contains illegal characters.

keepAliveInterval 太小了。keepAliveInterval is too small.

傳送回應以完成 WebSocket 信號交換時發生錯誤。An error occurred when sending the response to complete the WebSocket handshake.

備註

這項作業不會封鎖。This operation will not block. 在接受 WebSocket 連線之後,傳回的 Task<TResult> 物件將會完成。The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

接收緩衝區的大小為16385個位元組。The size of the receive buffer is 16,385 bytes.

另請參閱

AcceptWebSocketAsync(String, Int32, TimeSpan)

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定、接收緩衝區大小和 WebSocket Keep-alive 間隔。Accept a WebSocket connection specifying the supported WebSocket sub-protocol, receive buffer size, and WebSocket keep-alive interval as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::WebSockets::HttpListenerWebSocketContext ^> ^ AcceptWebSocketAsync(System::String ^ subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval);
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync (string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval);
member this.AcceptWebSocketAsync : string * int * TimeSpan -> System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext>
Public Function AcceptWebSocketAsync (subProtocol As String, receiveBufferSize As Integer, keepAliveInterval As TimeSpan) As Task(Of HttpListenerWebSocketContext)

參數

subProtocol
String

支援的 WebSocket 子通訊協定。The supported WebSocket sub-protocol.

receiveBufferSize
Int32

接收緩衝區大小 (以位元組為單位)。The receive buffer size in bytes.

keepAliveInterval
TimeSpan

WebSocket 通訊協定保持連接間隔 (以毫秒為單位)。The WebSocket protocol keep-alive interval in milliseconds.

傳回

代表非同步作業的工作物件。The task object representing the asynchronous operation. 工作物件上的 Result 屬性會傳回 HttpListenerWebSocketContext 物件。The Result property on the task object returns an HttpListenerWebSocketContext object.

例外狀況

subProtocol 為空字串subProtocol is an empty string -或--or- subProtocol 包含不合法的字元。subProtocol contains illegal characters.

keepAliveInterval 太小了。keepAliveInterval is too small.

-或--or- receiveBufferSize 小於 16 位元組。receiveBufferSize is less than 16 bytes -或--or- receiveBufferSize 大於 64KB。receiveBufferSize is greater than 64K bytes.

傳送回應以完成 WebSocket 信號交換時發生錯誤。An error occurred when sending the response to complete the WebSocket handshake.

備註

這項作業不會封鎖。This operation will not block. 在接受 WebSocket 連線之後,傳回的 Task<TResult> > 物件將會完成。The returned Task<TResult> > object will complete after the WebSocket connection has been accepted.

另請參閱

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

以非同步作業的方式接受 WebSocket 連接,並指定支援的 WebSocket 附屬通訊協定、接收緩衝區大小、WebSocket Keep-alive 間隔和內部緩衝區。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.

public:
 System::Threading::Tasks::Task<System::Net::WebSockets::HttpListenerWebSocketContext ^> ^ AcceptWebSocketAsync(System::String ^ subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<System::Byte> internalBuffer);
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync (string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer);
member this.AcceptWebSocketAsync : string * int * TimeSpan * ArraySegment<byte> -> System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext>
Public Function AcceptWebSocketAsync (subProtocol As String, receiveBufferSize As Integer, keepAliveInterval As TimeSpan, internalBuffer As ArraySegment(Of Byte)) As Task(Of HttpListenerWebSocketContext)

參數

subProtocol
String

支援的 WebSocket 子通訊協定。The supported WebSocket sub-protocol.

receiveBufferSize
Int32

接收緩衝區大小 (以位元組為單位)。The receive buffer size in bytes.

keepAliveInterval
TimeSpan

WebSocket 通訊協定保持連接間隔 (以毫秒為單位)。The WebSocket protocol keep-alive interval in milliseconds.

internalBuffer
ArraySegment<Byte>

這項作業要使用的內部緩衝區。An internal buffer to use for this operation.

傳回

代表非同步作業的工作物件。The task object representing the asynchronous operation. 工作物件上的 Result 屬性會傳回 HttpListenerWebSocketContext 物件。The Result property on the task object returns an HttpListenerWebSocketContext object.

例外狀況

subProtocol 為空字串subProtocol is an empty string -或--or- subProtocol 包含不合法的字元。subProtocol contains illegal characters.

keepAliveInterval 太小了。keepAliveInterval is too small.

-或--or- receiveBufferSize 小於 16 位元組。receiveBufferSize is less than 16 bytes -或--or- receiveBufferSize 大於 64KB。receiveBufferSize is greater than 64K bytes.

傳送回應以完成 WebSocket 信號交換時發生錯誤。An error occurred when sending the response to complete the WebSocket handshake.

備註

這項作業不會封鎖。This operation will not block. 在接受 WebSocket 連線之後,傳回的 Task<TResult> 物件將會完成。The returned Task<TResult> object will complete after the WebSocket connection has been accepted.

另請參閱

適用於