예제 #1
0
        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);
        }
예제 #2
0
 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);
 }