private void OnClientConnect(IAsyncResult asyn) { // create a new socket for the connection var clientSocket = ListenerSocker.EndAccept(asyn); // oh joy we have a connection - lets tell everybody about it LogLine(DateTime.Now + "> new connection from " + clientSocket.LocalEndPoint, ServerLogLevel.Subtle); // keep track of the new guy var clientConnection = new WebSocketConnection(clientSocket); // shake hands to give the new client a warm welcome ShakeHands(clientSocket, clientConnection); clientConnection.ListenIncomingData(); Connections.Add(clientConnection); clientConnection.Disconnected += new WebSocketDisconnectedEventHandler(ClientDisconnected); // invoke the connection event if (ClientConnected != null) { ClientConnected(clientConnection, EventArgs.Empty); } if (LogLevel != ServerLogLevel.Nothing) { clientConnection.DataReceived += new DataReceivedEventHandler(DataReceivedFromClient); } // listen for more clients ListenForClients(); }