Category : boost-beast

I was experimenting with boost asio with fibers and found that boost::this_fiber::yield() and boost::this_fiber::sleep_for(x) seem to behave differently when using the round robin asio scheduler provided in fibers examples. The setup is that we have one thread create two fibers which loop indefinitely: Fiber 1 uses async read with a beast websocket. while (true) { ..

Read more

I’m trying to use scio_beast in a project. I understand its rather unfinished, but that should not matter much. I’ve managed to get it working pretty well. I’m trying to connect to a server behind CloudFlare now, an I understand I need SNI for that to work. Given the following: using tcp = boost::asio::ip::tcp; // ..

Read more

I am trying boost::beast examples, I came across to this piece of code. void on_write(beast::error_code ec, std::size_t byte_transferred) { if (ec) return fail(ec, "write"); http::async_read(m_tcp_stream, m_buffer, m_response, beast::bind_front_handler( &Session::on_read, shared_from_this())); } void on_read(beast::error_code ec, std::size_t bytes_transferred) { if (ec) return fail(ec, "read"); //std::cout << m_response << std::endl; write_on_file(m_response); m_tcp_stream.socket().shutdown(tcp::socket::shutdown_both, ec); if (ec && ec != ..

Read more

// Connection establisher class class CSSLConn: public std::enable_shared_from_this<CSSLConn> { : : }; // Class for maintaining the thread pool class CHttpClient { // vector to hold connction objects std::vector <std::shared_ptr<CSSLConn>> m_sslConnObj{}; // main method call this to create connection void CHttpClient::Initialize(int nThreads) { for (int x = 0; x < nThreadCount; ++x) { worker_threads_.create_thread(boost::bind(&CHttpClient::WorkerThread, this)); ..

Read more

I am trying to parse HTTPS response using boost::beast::http::parser. My parser is defined like this: boost::beast::http::parser<false, boost::beast::http::string_body> response_parser; And the callback for async read is like this: void AsyncHttpsRequest::on_response_read(const boost::system::error_code &error_code, uint32_t bytes_transferred) { if (bytes_transferred > 0) { response_parser.put(boost::asio::buffer(data_buffer, bytes_transferred), http_error_code); std::cout << "Parser status: " << http_error_code.message() << std::endl; std::cout << "Read " ..

Read more

I’m trying to build my project that uses boost beast library with cmake. When I use only boost asio library everything builds okay. But when I add boost/beast/http.hpp header when cmake gives a huge amount of errors. CMake file: cmake_minimum_required(VERSION 3.10) project(ConsoleChat.Server) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost 1.75.0 REQUIRED COMPONENTS system filesystem) add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) ..

Read more

Here’s my header file for a WebSocket client: namespace beast = boost::beast; namespace asio = boost::asio; class WebSocketClient { public: explicit WebSocketClient(asio::io_context &ioc); private: using stream_type = beast::websocket::stream<beast::ssl_stream<beast::tcp_stream>>; using ssl_context_type = asio::ssl::context; asio::ip::tcp::resolver resolver_; stream_type ws_; ssl_context_type get_ssl_context(); }; And here’s my definition: WebSocketClient::WebSocketClient(asio::io_context &ioc) : resolver_(asio::make_strand(ioc)), ws_(asio::make_strand(ioc), get_ssl_context()) { } asio::ssl::context WebSocketClient::get_ssl_context() { return ..

Read more