private void OnClientAccepted(IAsyncResult ar) { try { var connected = listener.EndAcceptTcpClient(ar); var client = new ClientManager(connected, this); client.OnMessage += OnMessage; lock (connectedClients) { connectedClients.Add(client); client.OnReading(); ConsoleMessenger.Log(ConsoleMessenger.Prefix.Message, "Added new client"); } } catch (Exception e) { if (e.GetType() == typeof(SocketException) && ((SocketException)e).ErrorCode == 10004) { ConsoleMessenger.Log(ConsoleMessenger.Prefix.Error, e.Message); } else { throw; } } }