int main(int argc, char** argv) { try { boost::asio::io_service io_service; auto parameters = get_parameters(argc, argv); auto endpoint = parameters->rawsocket_endpoint(); auto realm = parameters->realm(); auto debug = parameters->debug(); boost::future<void> started; boost::future<void> called; boost::future<void> stopped; std::unique_ptr<autobahn::wamp_tcp_component> component( new autobahn::wamp_tcp_component( io_service, endpoint, realm, debug)); started = component->start().then([&](boost::future<void>) { autobahn::wamp_call_options call_options; call_options.set_timeout(std::chrono::seconds(10)); auto session = component->session(); std::tuple<uint64_t, uint64_t> arguments(23, 777); called = session->call("com.examples.calculator.add", arguments, call_options).then( [&](boost::future<autobahn::wamp_call_result> result) { try { uint64_t sum = result.get().argument<uint64_t>(0); std::cerr << "call result: " << sum << std::endl; } catch (const std::exception& e) { std::cerr << "call failed: " << e.what() << std::endl; } stopped = component->stop().then([&](boost::future<void>) { io_service.stop(); }); }); }); io_service.run(); stopped.wait(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return -1; } return 0; }
int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared<autobahn::wamp_tcp_transport>( io, parameters->rawsocket_endpoint(), debug); // create a WAMP session that talks WAMP-RawSocket over TCP // auto session = std::make_shared<autobahn::wamp_session>(io, debug); transport->attach(std::static_pointer_cast<autobahn::wamp_transport_handler>(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future<void> connect_future; boost::future<void> start_future; boost::future<void> join_future; boost::future<void> leave_future; boost::future<void> stop_future; connect_future = transport->connect().then([&](boost::future<void> connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future<void> started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future<uint64_t> joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::tuple<std::string> arguments(std::string("hello")); session->publish("com.examples.subscriptions.topic1", arguments); std::cerr << "event published" << std::endl; leave_future = session->leave().then([&](boost::future<std::string> reason) { try { std::cerr << "left session (" << reason.get() << ")" << std::endl; } catch (const std::exception& e) { std::cerr << "failed to leave session: " << e.what() << std::endl; io.stop(); return; } stop_future = session->stop().then([&](boost::future<void> stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; transport->detach(); } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return 1; } return 0; }
int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared<autobahn::wamp_tcp_transport>( io, parameters->rawsocket_endpoint(), debug); auto session = std::make_shared<autobahn::wamp_session>(io, debug); transport->attach(std::static_pointer_cast<autobahn::wamp_transport_handler>(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future<void> connect_future; boost::future<void> start_future; boost::future<void> join_future; boost::future<void> provide_future; connect_future = transport->connect().then([&](boost::future<void> connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future<void> started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future<uint64_t> joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } provide_future = session->provide("com.examples.calculator.add2", &add2).then( [&](boost::future<autobahn::wamp_registration> registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); provide_future = session->provide("com.myapp.longop", &longop).then( [&](boost::future<autobahn::wamp_registration> registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return -1; } return 0; }
int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; boost::asio::ip::tcp::socket socket(io); // create a WAMP session that talks WAMP-RawSocket over TCP // bool debug = parameters->debug(); auto session = std::make_shared< autobahn::wamp_session<boost::asio::ip::tcp::socket, boost::asio::ip::tcp::socket>>(io, socket, socket, debug); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future<void> start_future; boost::future<void> join_future; socket.async_connect(parameters->rawsocket_endpoint(), [&](boost::system::error_code ec) { if (!ec) { std::cerr << "connected to server" << std::endl; start_future = session->start().then([&](boost::future<bool> started) { if (started.get()) { std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future<uint64_t> s) { std::cerr << "joined realm: " << s.get() << std::endl; session->provide("com.example.add2", &add2); }); } else { std::cerr << "failed to start session" << std::endl; io.stop(); } }); } else { std::cerr << "connect failed: " << ec.message() << std::endl; } } ); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return 1; } return 0; }
int main(int argc, char** argv) { try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; auto transport = std::make_shared<autobahn::wamp_tcp_transport>( io, parameters->rawsocket_endpoint()); bool debug = parameters->debug(); auto session = std::make_shared<autobahn::wamp_session>( io, transport, transport, debug); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future<void> start_future; boost::future<void> join_future; boost::future<void> leave_future; boost::future<void> stop_future; transport->async_connect([&](boost::system::error_code ec) { if (!ec) { std::cerr << "connected to server" << std::endl; start_future = session->start().then([&](boost::future<bool> started) { if (started.get()) { std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future<uint64_t> joined) { std::cerr << "joined realm: " << joined.get() << std::endl; std::tuple<std::string> arguments(std::string("hello")); session->publish("com.examples.subscriptions.topic1", arguments); std::cerr << "event published" << std::endl; leave_future = session->leave().then([&](boost::future<std::string> reason) { std::cerr << "left session (" << reason.get() << ")" << std::endl; stop_future = session->stop().then([&](boost::future<void> stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); }); } else { std::cerr << "failed to start session" << std::endl; io.stop(); } }); } else { std::cerr << "connect failed: " << ec.message() << std::endl; io.stop(); } } ); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 1; } return 0; }
int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "realm: " << parameters->realm() << std::endl; boost::asio::io_service io; boost::asio::ip::tcp::socket socket(io); bool debug = parameters->debug(); std::vector<std::string> auth_methods; auth_methods.push_back("wampcra"); std::string authid = "homer"; std::string secret = "secret123"; auto session = std::make_shared< auth_wamp_session<boost::asio::ip::tcp::socket, boost::asio::ip::tcp::socket>>(io, socket, socket, debug, secret); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future<void> start_future; boost::future<void> join_future; socket.async_connect(parameters->rawsocket_endpoint(), [&](boost::system::error_code ec) { if (!ec) { std::cerr << "connected to server" << std::endl; start_future = session->start().then([&](boost::future<bool> started) { if (started.get()) { std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm(), auth_methods, authid).then([&](boost::future<uint64_t> s) { std::cerr << "joined realm: " << s.get() << std::endl; io.stop(); }); } else { std::cerr << "failed to start session" << std::endl; io.stop(); } }); } else { std::cerr << "connect failed: " << ec.message() << std::endl; io.stop(); } } ); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } return 0; }