/// <summary> /// Close client websocket /// </summary> /// <param name="context"></param> /// <param name="msg"></param> private async Task Disconnect(Constants.WEBSOCKET_STATUS status) { if (socket.State == WebSocketState.CloseReceived) { //await ProcessSendBroadCast(userData.token + " disconnect"); //context.WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, // msg, CancellationToken.None).Wait(); LIST_CLIENT.Remove(key); await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, status.ToString(), CancellationToken.None); } }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="status"></param> /// <returns></returns> private async Task KickUser(string key, Constants.WEBSOCKET_STATUS status) { if (LIST_CLIENT.ContainsKey(key)) { var client = LIST_CLIENT[key].WebSocket as AspNetWebSocket; if (client.State == WebSocketState.Open) { LIST_CLIENT.Remove(key); await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, status.ToString(), CancellationToken.None); } } }