Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //
  2. // client.cpp
  3. // ~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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.  
  11. #include <iostream>
  12. #include <boost/array.hpp>
  13. #include <boost/asio.hpp>
  14.  
  15. using boost::asio::ip::tcp;
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19. #ifdef _WIN32
  20. // Make english boost console output
  21. SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
  22. #endif
  23.  
  24. try
  25. {
  26. boost::asio::io_service io_service;
  27. tcp::socket socket(io_service);
  28. socket.connect(tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 13));
  29.  
  30. for (;;)
  31. {
  32. boost::array<char, 128> buf;
  33. boost::system::error_code error;
  34.  
  35. size_t len = socket.read_some(boost::asio::buffer(buf), error);
  36.  
  37. if (error == boost::asio::error::eof)
  38. break; // Connection closed cleanly by peer.
  39. else if (error)
  40. throw boost::system::system_error(error); // Some other error.
  41.  
  42. std::cout.write(buf.data(), len);
  43. }
  44. }
  45. catch (std::exception& e)
  46. {
  47. std::cerr << e.what() << std::endl;
  48. }
  49.  
  50. system("pause");
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement