C++ Boost::Beast














































C++ Boost::Beast



Beast is a C++ header-only library serving as a foundation for writing interoperable networking libraries by providing low-level HTTP/1, WebSocket, and networking protocol vocabulary types and algorithms using the consistent asynchronous model of Boost.Asio.

This library is designed for:

  • Symmetry: Algorithms are role-agnostic; build clients, servers, or both.
  • Ease of Use: Boost.Asio users will immediately understand Beast.
  • Flexibility: Users make the important decisions such as buffer or thread management.
  • Performance: Build applications handling thousands of connections or more.
  • The basis for Further Abstraction. Components are well-suited for building upon

Beast requires:

  • C++11: Robust support for most language features.
  • Boost: Beast only works with Boost, not stand-alone Asio
  • OpenSSL: Required to build the tests, examples, and to use TLS/Secure sockets.

Boost.Asio:
Boost.Asio may be used to perform both synchronous and asynchronous operations on I/O objects such as sockets. Before using Boost.Asio it may be useful to get a conceptual picture of the various parts of Boost.Asio, your program, and how they work together.


As an introductory example, let's consider what happens when we perform a connect operation on a socket. We shall start by examining synchronous operations.

sync_op

The suitable compilers for Beast:  msvc-14+, gcc 4.8.4+, clang 3.6

Header:

#include <boost/asio.hpp>

Syntax of io_context object:

boost::asio::io_context io_context;

Syntax of TCP Sockets:


boost::asio::ip::tcp::socket socket(io_context);

Program:


#include <iostream>
#include <boost/asio.hpp>
int main()
{
  boost::asio::io_context io;
  boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5));
  t.wait();
    std::cout << "CPPSECRETS is very good handbooks for python and c++ professionals" << std::endl;

  return 0;
}


Output:








Comments