daytime_client.cpp 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // daytime_client.cpp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #include <iostream>
  11. #include <string>
  12. #include <boost/asio.hpp>
  13. using boost::asio::ip::tcp;
  14. int main(int argc, char* argv[])
  15. {
  16. try
  17. {
  18. if (argc != 2)
  19. {
  20. std::cerr << "Usage: daytime_client <host>" << std::endl;
  21. return 1;
  22. }
  23. tcp::iostream s(argv[1], "daytime");
  24. if (!s)
  25. {
  26. std::cout << "Unable to connect: " << s.error().message() << std::endl;
  27. return 1;
  28. }
  29. std::string line;
  30. std::getline(s, line);
  31. std::cout << line << std::endl;
  32. }
  33. catch (std::exception& e)
  34. {
  35. std::cout << "Exception: " << e.what() << std::endl;
  36. }
  37. return 0;
  38. }