private async Task Handle(HttpContext context, WebsocketClient webSocket, IConfigService configService) { var buffer = new byte[1024 * 2]; WebSocketReceiveResult result = null; do { result = await webSocket.Client.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); webSocket.LastHeartbeatTime = DateTime.Now; var message = await ConvertWebsocketMessage(result, buffer); if (message == "ping") { //如果是ping,回复本地数据的md5版本 var appId = context.Request.Headers["appid"]; var md5 = await configService.AppPublishedConfigsMd5Cache(appId); var md5Data = Encoding.UTF8.GetBytes($"V:{md5}"); await webSocket.Client.SendAsync(new ArraySegment <byte>(md5Data, 0, md5Data.Length), WebSocketMessageType.Text, true, CancellationToken.None); } else { //如果不是心跳消息,回复0 var zeroData = Encoding.UTF8.GetBytes("0"); await webSocket.Client.SendAsync(new ArraySegment <byte>(zeroData, 0, zeroData.Length), WebSocketMessageType.Text, true, CancellationToken.None); } }while (!result.CloseStatus.HasValue); _logger.LogInformation($"Websocket close , closeStatus:{result.CloseStatus} closeDesc:{result.CloseStatusDescription}"); await _websocketCollection.RemoveClient(webSocket, result.CloseStatus, result.CloseStatusDescription); }