private void AddClient(SocketClient client)
 {
     lock (this)
     {
         _clients.Add(client);
     }
 }
 private void RemoveClient(SocketClient client)
 {
     lock (this)
     {
         _clients.Remove(client);
     }
 }
 private void SendClientMessage(SocketClient client, string message)
 {
     try
     {
         client.Send(message);
     }
     catch (Exception ex)
     {
         client.Dispose();
     }
 }
        private void OnConnect(IAsyncResult asyncResult)
        {
            try
            {
                // Block until a client connects
                Socket socket = _serverSocket.EndAccept(asyncResult);

                SocketClient client = new SocketClient(socket);

                int currentActiveConnectionsCount = _clients.Count;
                if (currentActiveConnectionsCount < MaxConnections)
                {
                    try
                    {
                        //client.Send(""); here we could handle some handshake
                        AddClient(client);
                    }
                    catch
                    {
                        client.Dispose();
                    }
                }
                else
                {
                    //client.Send("Sorry - Too many connections.\r\n");
                    client.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (_serverSocket != null)
                {
                    _serverSocket.BeginAccept(new AsyncCallback(OnConnect), null);
                }
            }
        }