Skip to content

Boost Beast HTTP/Websocket C++ 20 coroutine demo app

Notifications You must be signed in to change notification settings

xzz53/beast-coroutine-demo

Repository files navigation

Boost Beast HTTP/Websocket C++ 20 coroutine demo app

Build dependencies (older versions may be compatible, but have not been tested against)

  • gcc 11.1, cmake
  • boost 1.78
  • python >=3.6, aiohttp 3.8.1 (for sleepy-server.py)
  • websocat (for testing)

Building

mkdir build && cmake -B build && cmake --build build

Sanitizers may be enabled using -DSANITIZE_ADDRESS=On, -DSANITIZE_THREAD=On, -DSANITIZE_MEMORY=On, -DSANITIZE_UNDEFINED=On cmake flags.

Running

The basic operation mode of the demo server is to receive space separated lists of URLs from multiple clients via websocket, fetch them concurrently via HTTP and return results to the clients as soon as all HTTP requests are completed. At this time the fetcher is rather simplistic: it ignores redirects and does not support https. Included test http server (sleepy-server) serves URLs like http://localhost:8081/delay, where delay is a real number, by sleeping for delay seconds and returning a single-line response. It offloads CPU-intensive request handling to a separate thread pool, thus preventing IO thread from blocking. Note that thread pool has fixed size of 2 threads now, so the server can process at most 2 requests simultaneously. OTOH it has no limits on accepting requests at any time.

In order to start the demo, run the following commands: In shell 1:

./build/sleepy-server

In shell 2:

./build/websocket-proxy

Then, in shell 3, try sending requests like

echo http://localhost:8081/2 http://localhost:8081/3 http://localhost:8081/4 | websocat ws://127.0.0.1:8082

Concurrent requests are supported, you can try it out by running multiple websocats in parallel.

About

Boost Beast HTTP/Websocket C++ 20 coroutine demo app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published