private void Handler(Socket socket, IOMultiPlex revents) { try { var id = socket.Recv(); DiscardEmptyLine(socket); var datagram = socket.RecvAll(Encoding.UTF8); var request = _formatter.DeserializeRequest(datagram); _work(request, response => socket.SendDatagram(id, _formatter.Serialize(response))); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = ConsoleColor.White; } }