]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // daytime_client.cpp | |
3 | // ~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2016 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 <string> | |
13 | #include <boost/asio.hpp> | |
14 | ||
15 | using boost::asio::ip::tcp; | |
16 | ||
17 | int main(int argc, char* argv[]) | |
18 | { | |
19 | try | |
20 | { | |
21 | if (argc != 2) | |
22 | { | |
23 | std::cerr << "Usage: daytime_client <host>" << std::endl; | |
24 | return 1; | |
25 | } | |
26 | ||
27 | tcp::iostream s(argv[1], "daytime"); | |
28 | if (!s) | |
29 | { | |
30 | std::cout << "Unable to connect: " << s.error().message() << std::endl; | |
31 | return 1; | |
32 | } | |
33 | ||
34 | std::string line; | |
35 | std::getline(s, line); | |
36 | std::cout << line << std::endl; | |
37 | } | |
38 | catch (std::exception& e) | |
39 | { | |
40 | std::cout << "Exception: " << e.what() << std::endl; | |
41 | } | |
42 | ||
43 | return 0; | |
44 | } |