public async Task SendAllExcept(string[] id, SocketMessage message) { foreach (var connection in Connections.Where(c => !id.Contains(c.Id))) { await Send(connection.Socket, message); } }
public async Task SendAll(SocketMessage message) { foreach (var connection in Connections.Where(c => c.Socket.State == WebSocketState.Open)) { await Send(connection.Socket, message); } }
public async Task SendTo(string id, SocketMessage message) { foreach (var item in Connections.Where(c => c.Id == id)) { await Send(item.Socket, message); } }
private async Task Send(WebSocket webSocket, SocketMessage message) { if (webSocket != null && webSocket.State == WebSocketState.Open) { var value = new ArraySegment<byte>(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))); await webSocket.SendAsync(value, WebSocketMessageType.Text, true, CancellationToken.None); } }