Beast Logo

PrevUpHomeNext

Making connections

Connections are established by using the interfaces which already exist for the next layer. For example, making an outgoing connection:

std::string const host = "mywebapp.com";
boost::asio::io_service ios;
boost::asio::ip::tcp::resolver r{ios};
beast::websocket::stream<boost::asio::ip::tcp::socket> ws{ios};
boost::asio::connect(ws.next_layer(),
    r.resolve(boost::asio::ip::tcp::resolver::query{host, "ws"}));

Accepting an incoming connection:

void do_accept(boost::asio::ip::tcp::acceptor& acceptor)
{
    beast::websocket::stream<boost::asio::ip::tcp::socket> ws{acceptor.get_io_service()};
    acceptor.accept(ws.next_layer());
}
[Note] Note

Examples use synchronous interfaces for clarity of exposition.


PrevUpHomeNext