Category : boost-asio

I am getting a compile error in the following code: boost::asio::io_context io_context; server server1(io_context, 1980); boost::thread t(boost::bind(&boost::asio::io_context::run, &io_context)); Where the definition of the server class is: using boost::asio::ip::tcp; class server { public: server(boost::asio::io_context& io_context, short port) : acceptor_(io_context, tcp::endpoint(tcp::v4(), port)) { do_accept(); } private: void do_accept() { acceptor_.async_accept( [this](boost::system::error_code ec, tcp::socket socket) { if (!ec) ..

Read more

I have a composed async operation which uses non-boost Asio 1.18.1 to resolve and connect to a host and service. I want it to pass the actual endpoint it connects to, to the completion token. Right now it does not. #include <iostream> #include <string_view> #include "asio.hpp" template <typename Token, typename Executor> auto async_connect_to(Executor&& executor, asio::ip::tcp::socket& ..

Read more

I’m using c++20 with boost awaitable for writing async server/client. One of the features of boost asio socket is that it is not safe to call concurrently async_write on a socket, even with 1 thread. Basically i’m trying to avoid a situation where: calling and suspending co_await async_write(sock, buffer(std::string{"data to send"}), use_awaitable); will not interfere ..

Read more

I use the boost asio ssl server from this example. I’ve modified the code in this way private: void do_handshake() { auto self(shared_from_this()); socket_.async_handshake( boost::asio::ssl::stream_base::server, [this, self](const boost::system::error_code& error) { if (!error) { std::cout << "client: " << socket_.lowest_layer().remote_endpoint().address().to_string() << std::endl; read_header(); } } ); } void read_header() { auto self(shared_from_this()); buffer_.clear(); buffer_.resize(protocol::header_size); boost::asio::async_read( socket_, ..

Read more

I want to send 3-4 headers to the WebSocket server that I have and the headers are action = subscribe,userID = <some email address>,agentID =831C5DFC-1643-40C4-A5A3-9C918556D3A1 , I am unable to understand how to send these headers to the server, like what is the typical method? this is my client code👇🏼 #include <boost/beast/http.hpp> #include <boost/asio/connect.hpp> #include ..

Read more