Boost.Beast Documentation

repository·develop·Indexed 26 days ago

https://github.com/boostorg/beast

A low-level C++11 header-only library providing HTTP/1 and WebSocket protocol implementations built on top of Boost.Asio. Designed for high-performance, asynchronous networking applications, Boost.Beast is role-agnostic and flexible regarding buffer and thread management.

Tokens
858
Snippets
4
Records
7
Agent score
39%

What's inside Boost.Beast

  1. Overview of Boost.Beast

    develop
    Boost.Beast is a C++11 header-only library that provides low-level HTTP/1, WebSocket, and networking protocol vocabulary types and algorithms. It is built on top of Boost.Asio and uses its consistent asynchronous model. Beast is designed to be role-agnostic (allowing for both client and server implementations), flexible regarding buffer and thread management, and highly performant for handling large numbers of connections.
  2. Build Beast tests and examples

    develop

    Ensure the b2 (bjam) tool is in your PATH. Use the following commands to build specific components (assuming cxxstd=11):

    • Build Tests: b2 -j2 libs/beast/test cxxstd=11
    • Build Examples: b2 -j2 libs/beast/example cxxstd=11
    • Build Documentation: b2 libs/beast/doc (requires Doxygen and Saxon)

    Note: -j2 tells the build system to use two processors.

    export PATH=$PWD:$PATH
    b2 -j2 libs/beast/test cxxstd=11
    b2 -j2 libs/beast/example cxxstd=11
    b2 libs/beast/doc
  3. Build Boost.Beast and its dependencies

    develop

    To build the Boost libraries and Beast, use the bjam (or b2) tool.

    First, clone the Boost superproject to work with Beast 'in-tree':

    git clone --recursive https://github.com/boostorg/boost.git
    cd boost

    Then, bootstrap the build tool:

    • Linux/Mac: ./bootstrap.sh
    • Windows: .\BOOTSTRAP.BAT
    git clone --recursive https://github.com/boostorg/boost.git
    cd boost
    ./bootstrap.sh
  4. Install OpenSSL for building tests and examples

    develop

    Building Beast's tests and examples requires OpenSSL. Depending on your platform, follow these steps:

    Ubuntu/Debian

    sudo apt install libssl-dev

    Windows (using vcpkg)

    CMD:

    vcpkg install openssl --triplet x32-windows
    SET OPENSSL_ROOT=path\installed\x32-windows

    PowerShell:

    vcpkg install openssl --triplet x32-windows
    $env:OPENSSL_ROOT = "path\x32-windows"

    Mac OS (using Homebrew)

    brew install openssl
    export OPENSSL_ROOT=$(brew --prefix openssl)
    cp ./libs/beast/tools/user-config.jam $HOME
  5. Generate Visual Studio solutions using CMake

    develop

    You can use CMake to generate Visual Studio project files. Replace path with your actual vcpkg installation path.

    For 32-bit (x86):

    cmake -G "Visual Studio 17 2022" -A win32 -B bin -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="C:/boost/libs/beast/cmake/toolchains/msvc.cmake"

    For 64-bit (x64):

    cmake -G "Visual Studio 17 2022" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="C:/boost/libs/beast/cmake/toolchains/msvc.cmake"
  6. Requirements for using Boost.Beast

    develop

    To use Boost.Beast, you must meet the following requirements:

    • C++11: Support for most language features.
    • Boost: Specifically Boost.Asio and other related Boost components.
    • OpenSSL: Required if you intend to use TLS/Secure sockets.
    • Compiler: For Microsoft Visual C++, Visual Studio 2017 or later is required.

    If you are using coroutines, you must also link with the Boost.Coroutine library.