public void Start(Action<WebSocketConnection, WebSocketData> onData, Action<WebSocketConnection> onDisconnect) { Dictionary<System.Net.Sockets.TcpClient, WebSocketConnection> conn = new Dictionary<System.Net.Sockets.TcpClient, WebSocketConnection>(); TCPServer serv = new TCPServer(1000); serv.Start( (client, data) => { if (!conn.ContainsKey(client)) { PerformHandshake(client, data); conn[client] = new WebSocketConnection(onData, client); } else { conn[client].Feed(data); } }, disconnected => { onDisconnect(conn[disconnected]); conn.Remove(disconnected); } ); foreach (var kvpair in conn) { kvpair.Key.Close(); } }