9 #include <boost/asio.hpp>
11 #include <boost/array.hpp>
14 int main (
int argc,
char* argv[]) {
17 std::string lHostname =
"localhost";
21 const std::string lServiceName =
"aria";
29 boost::asio::io_service lIOService;
31 boost::asio::ip::tcp::resolver lResolver (lIOService);
33 boost::asio::ip::tcp::resolver::query lQuery (lHostname, lServiceName);
35 boost::asio::ip::tcp::resolver::iterator itEndPoint =
36 lResolver.resolve (lQuery);
37 boost::asio::ip::tcp::resolver::iterator lEnd;
39 boost::asio::ip::tcp::socket lSocket (lIOService);
40 boost::system::error_code lError = boost::asio::error::host_not_found;
43 while (lError && itEndPoint != lEnd) {
44 const boost::asio::ip::tcp::endpoint lEndPoint = *itEndPoint;
47 std::cout <<
"Testing end point: " << std::endl;
50 lSocket.connect (lEndPoint, lError);
56 throw boost::system::system_error (lError);
61 const boost::asio::ip::tcp::endpoint lValidEndPoint;
62 std::cout <<
"Valid end point: " << lValidEndPoint << std::endl;
65 const std::string lMessage (
"Hello AirInv Server!");
66 boost::asio::write (lSocket, boost::asio::buffer (lMessage),
67 boost::asio::transfer_all(), lError);
70 boost::array<char, 256> lBuffer;
72 size_t lLength = lSocket.read_some (boost::asio::buffer(lBuffer), lError);
75 if (lError && lError != boost::asio::error::eof) {
76 throw boost::system::system_error (lError);
80 std::cout <<
"Reply from the server: ";
81 std::cout.write (lBuffer.data(), lLength);
82 std::cout << std::endl;
84 }
catch (std::exception& lException) {
85 std::cerr << lException.what() << std::endl;