static async Task Broadcast(ResponseMessage msg) { byte[] toSend = Encoding.UTF8.GetBytes(msg.ToString()); List<Task> tasks = new List<Task>(); foreach (WebSocketsAPIHandler handler in Clients.Values) { tasks.Add(handler.WebSocketContext.WebSocket.SendAsync(new ArraySegment<byte>(toSend), WebSocketMessageType.Text, true, CancellationToken.None)); } await Task.WhenAll(tasks); }
async Task Send(ResponseMessage msg) { byte[] toSend = Encoding.UTF8.GetBytes(msg.ToString()); await WebSocketContext.WebSocket.SendAsync(new ArraySegment<byte>(toSend), WebSocketMessageType.Text, true, CancellationToken.None); }