// 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 #include int main(int argc, char* argv[]) { if (argc > 3) { std::cerr << "Usage: stream_server [host [port]]" << std::endl; std::cerr << "Default host is 'any://localhost', default port is none." << std::endl; return -1; } try { // retrieve parameter values saga::url url; if (argc > 1) url = argv[1]; else url = "any://localhost"; if (argc > 2) url.set_port(boost::lexical_cast(argv[2])); std::cout << "Serving " << url << std::endl; // actual functionality saga::stream::server service(url); while(1) { saga::stream::stream strm = service.serve(); std::cout << "Established connection from: " << strm.get_url() << "!" << std::endl; char buff[255]; saga::ssize_t read_bytes = strm.read(saga::buffer(buff)); strm.write (saga::buffer(buff, read_bytes)); } } 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; }