多少并发等待

时间:2016-01-17 20:18:26

标签: c# websocket async-await

采取形式保罗巴图姆的例子(https://github.com/paulbatum/WebSocket-Samples/blob/master/HttpListenerWebSocketEcho/Server/Server.cs)删除所有尝试/捕获为了lisiblity:

private async void ProcessRequest(HttpListenerContext listenerContext)
{
    WebSocketContext webSocketContext = await listenerContext.AcceptWebSocketAsync(subProtocol: null);
    WebSocket webSocket = webSocketContext.WebSocket;                                           

    byte[] receiveBuffer = new byte[1024];

    while (webSocket.State == WebSocketState.Open)
    {
        WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), CancellationToken.None);
        await webSocket.SendAsync(new ArraySegment<byte>(receiveBuffer, 0, receiveResult.Count), WebSocketMessageType.Binary, receiveResult.EndOfMessage, CancellationToken.None);
    }
}

如果我理解得很清楚,每次新客户端连接时,都会设置一个新的“实例”等待webSocket.ReceiveAsync()

我想知道这种方法可以处理多少客户端;换句话说,有多少等待可能是“待定”?

0 个答案:

没有答案