Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Asio Refresher

[Warning] Warning

Beast does not manage sockets, make outgoing connections, accept incoming connections, handle timeouts, close endpoints, do name lookups, deal with TLS certificates, perform authentication, or otherwise handle any aspect of connection management. This is left to the interfaces already existing on the underlying streams.

Library stream algorithms require a boost::asio::ip::tcp::socket, boost::asio::ssl::stream, or other Stream object that has already established communication with an endpoint. This example is provided as a reminder of how to work with sockets:

char const* const host = "www.example.com";
boost::asio::ip::tcp::resolver r{ioc};
boost::asio::ip::tcp::socket stream{ioc};
auto const results = r.resolve(host, "http");
boost::asio::connect(stream, results.begin(), results.end());

// At this point `stream` is a connected to a remote
// host and may be used to perform stream operations.

Throughout this documentation identifiers with the following names have special meaning:

Table 1.1. Global Variables

Name

Description

ioc

A variable of type boost::asio::io_context which is running on one separate thread, and upon which an boost::asio::executor_work_guard object has been constructed.

sock

A variable of type boost::asio::ip::tcp::socket which has already been connected to a remote host.

ssl_sock

A variable of type boost::asio::ssl::stream<boost::asio::ip::tcp::socket> which is already connected and has handshaked with a remote host.

ws

A variable of type websocket::stream<boost::asio::ip::tcp::socket> which is already connected with a remote host.



PrevUpHomeNext