// Copyright (c) 2005-2008 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include int main(int argc, char* argv[]) { if (argc > 3) { std::cerr << "Usage: stream_client [host [port]]" << std::endl; std::cerr << "Default host is 'any://localhost', default port is none." << std::endl; return -1; } try { // retrieve parameter values std::string host; std::string port; if (argc > 1) host = argv[1]; else host = "any://localhost"; if (argc > 2) port = argv[2]; // actual functionality std::string url (host); if (!port.empty()) host += ":" + port; std::cout << "Trying to connect to " << (host) << std::endl; saga::stream::stream strm(url); strm.connect(); std::cout << "Connected!" << std::endl; std::string msg("test from client\n"); std::cout << "Sending: " << msg; strm.write(saga::buffer(msg)); char buff[255]; saga::ssize_t read_bytes = strm.read(saga::buffer(buff)); std::cout << "Received: " << std::string(buff, read_bytes) << std::endl; } catch (saga::exception const& e) { std::cerr << "saga::exception caught: " << e.what () << std::endl; return -3; } catch (std::exception const& e) { std::cerr << "std::exception caught: " << e.what () << std::endl; return -2; } catch (...) { std::cerr << "unexpected exception caught" << std::endl; return -1; } return 0; }