Category : boost-asio

I’m using boost::asio to handle network communication between my program and remote server. To establish a connection with a server I do the following sequence of operations: namespace ba = boost::asio; boost::shared_ptr<ba::ssl::context> ssl_ctx; boost::shared_ptr<boost::asio::io_context> ios; // initialized boost::shared_ptr<ba::ssl::stream<tcp::socket>> ssl_socket; ssl_ctx.reset(new ba::ssl::context(boost::asio::ssl::context_base::method::sslv23)); ssl_ctx->set_verify_mode(ba::ssl::verify_peer); ssl_ctx->add_certificate_authority(ba::buffer(certs.data(), certs.size())); ssl_socket.reset(new ba::ssl::stream<tcp::socket>(*ios, *ssl_ctx)); auto& socket = ssl_socket->next_layer(); ba::ip::tcp::resolver::iterator ep_iter; // target ..

Read more

I am creating an udp client pool. The servers will be some other applications running in different computers, and they are suppoused to be alive from beginning. Using a configurable file (not important to problem in example so not included) one to several clients are created so they connect to those servers (1 to 1 ..

Read more

I’m trying to implement two-way multicast UDP communication using Boost.Asio. Actually what I need is client-server architecture. I used these tutorials and examples and modified them: https://www.boost.org/doc/libs/1_71_0/doc/html/boost_asio/example/cpp11/multicast/receiver.cpp https://www.boost.org/doc/libs/1_71_0/doc/html/boost_asio/example/cpp11/multicast/sender.cpp https://www.boost.org/doc/libs/1_71_0/doc/html/boost_asio/example/cpp11/futures/daytime_client.cpp https://www.boost.org/doc/libs/1_71_0/doc/html/boost_asio/tutorial/tutdaytime6.html Futures daytime client and daytime server works perfectly fine, unless I use multicast address for it, which I have to. It just doesn’t communicate. I ..

Read more

I am using the libraries websocketcpp and boost 1.71. The code used to work with boost 1.58 but after upgrading both libraries, it won’t compile. The C++ compiler is g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 and the code is the following: using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json; using websocketpp::connection_hdl; using websocketpp::lib::placeholders::_1; using websocketpp::lib::placeholders::_2; using websocketpp::lib::bind; //……. { ..

Read more

I have a fairly simple use case. I would like to read from a boost socket using boost::asio::read, but with a timeout for the read call. I.e. If nothing nothing is read from the socket in 5 seconds, the call should terminate/throw-an-error/whatever. The code without a timeout is shown below: Json::Value Client::MakeRequest(const std::string &ip_addr, unsigned ..

Read more

I created a simple wrapper class for boost::asio::io_context in order to pack together: boost::asio::io_context boost::asio::work_guard std::thread (or boost::thread) Posting tasks and then coming to the point where ~worket_t is invoked, the thread seems to terminate the process since it is still join-able even if in ~worker_t() the thread is supposedly joined. ~thread() // this is ..

Read more