3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Examples</title>
5 <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../index.html" title="Chapter 1. Boost.Beast">
8 <link rel="up" href="../index.html" title="Chapter 1. Boost.Beast">
9 <link rel="prev" href="quick_start/websocket_autobahn_testsuite.html" title="WebSocket (Autobahn|Testsuite)">
10 <link rel="next" href="using_io.html" title="Networking">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="quick_start/websocket_autobahn_testsuite.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="using_io.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="beast.examples"></a><a class="link" href="examples.html" title="Examples">Examples</a>
28 </h2></div></div></div>
30 Source code and build scripts for these programs are located in the <a href="../../../example" target="_top">example</a> directory.
33 <div class="titlepage"><div><div><h3 class="title">
34 <a name="beast.examples.clients"></a><a class="link" href="examples.html#beast.examples.clients" title="Clients">Clients</a>
35 </h3></div></div></div>
37 These HTTP clients submit a GET request to a server specified on the command
38 line, and prints the resulting response. The crawl client asynchronously
39 fetches the document root of the 10,000 top ranked domains, this may be used
40 to evaluate robustness. All asynchronous clients support timeouts.
42 <div class="informaltable"><table class="table">
61 Source File (using SSL)
74 <a href="../../../example/http/client/sync/http_client_sync.cpp" target="_top">http_client_sync.cpp</a>
79 <a href="../../../example/http/client/sync-ssl/http_client_sync_ssl.cpp" target="_top">http_client_sync_ssl.cpp</a>
91 <a href="../../../example/http/client/async/http_client_async.cpp" target="_top">http_client_async.cpp</a>
96 <a href="../../../example/http/client/async-ssl/http_client_async_ssl.cpp" target="_top">http_client_async_ssl.cpp</a>
103 HTTP, asynchronous using <a href="../../../../../doc/html/boost_asio/reference/system_executor.html" target="_top"><code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">system_executor</span></code></a>
110 <a href="../../../example/http/client/async-ssl-system-executor/http_client_async_ssl_system_executor.cpp" target="_top">http_client_async_ssl_system_executor.cpp</a>
122 <a href="../../../example/http/client/coro/http_client_coro.cpp" target="_top">http_client_coro.cpp</a>
127 <a href="../../../example/http/client/coro-ssl/http_client_coro_ssl.cpp" target="_top">http_client_coro_ssl.cpp</a>
134 HTTP crawl (asynchronous)
139 <a href="../../../example/http/client/crawl/http_crawl.cpp" target="_top">http_crawl.cpp</a>
148 These WebSocket clients connect to a server and send a message, then receive
149 a message and print the response before disconnecting. All asynchronous clients
152 <div class="informaltable"><table class="table">
171 Source File (using SSL)
179 WebSocket, synchronous
184 <a href="../../../example/websocket/client/sync/websocket_client_sync.cpp" target="_top">websocket_client_sync.cpp</a>
189 <a href="../../../example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp" target="_top">websocket_client_sync_ssl.cpp</a>
196 WebSocket, asynchronous
201 <a href="../../../example/websocket/client/async/websocket_client_async.cpp" target="_top">websocket_client_async.cpp</a>
206 <a href="../../../example/websocket/client/async-ssl/websocket_client_async_ssl.cpp" target="_top">websocket_client_async_ssl.cpp</a>
213 WebSocket, asynchronous using <a href="../../../../../doc/html/boost_asio/reference/system_executor.html" target="_top"><code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">system_executor</span></code></a>
220 <a href="../../../example/websocket/client/async-ssl-system-executor/websocket_client_async_ssl_system_executor.cpp" target="_top">websocket_client_async_ssl_system_executor.cpp</a>
232 <a href="../../../example/websocket/client/coro/websocket_client_coro.cpp" target="_top">websocket_client_coro.cpp</a>
237 <a href="../../../example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp" target="_top">websocket_client_coro_ssl.cpp</a>
244 <div class="section">
245 <div class="titlepage"><div><div><h3 class="title">
246 <a name="beast.examples.servers"></a><a class="link" href="examples.html#beast.examples.servers" title="Servers">Servers</a>
247 </h3></div></div></div>
249 These HTTP servers deliver files from a root directory specified on the command
250 line. All asynchronous servers support timeouts.
252 <div class="informaltable"><table class="table">
271 Source File (using SSL)
284 <a href="../../../example/http/server/sync/http_server_sync.cpp" target="_top">http_server_sync.cpp</a>
289 <a href="../../../example/http/server/sync-ssl/http_server_sync_ssl.cpp" target="_top">http_server_sync_ssl.cpp</a>
301 <a href="../../../example/http/server/async/http_server_async.cpp" target="_top">http_server_async.cpp</a>
306 <a href="../../../example/http/server/async-ssl/http_server_async_ssl.cpp" target="_top">http_server_async_ssl.cpp</a>
318 <a href="../../../example/http/server/coro/http_server_coro.cpp" target="_top">http_server_coro.cpp</a>
323 <a href="../../../example/http/server/coro-ssl/http_server_coro_ssl.cpp" target="_top">http_server_coro_ssl.cpp</a>
330 HTTP, stackless coroutine
335 <a href="../../../example/http/server/stackless/http_server_stackless.cpp" target="_top">http_server_stackless.cpp</a>
340 <a href="../../../example/http/server/stackless-ssl/http_server_stackless_ssl.cpp" target="_top">http_server_stackless_ssl.cpp</a>
347 HTTP, fast (optimized for speed)
352 <a href="../../../example/http/server/fast/http_server_fast.cpp" target="_top">http_server_fast.cpp</a>
361 HTTP, small (optimized for space)
366 <a href="../../../example/http/server/small/http_server_small.cpp" target="_top">http_server_small.cpp</a>
375 HTTP, flex (plain + SSL)
382 <a href="../../../example/http/server/flex/http_server_flex.cpp" target="_top">http_server_flex.cpp</a>
389 These WebSocket servers echo back any message received, keeping the session
390 open until the client disconnects. All asynchronous servers support timeouts.
392 <div class="informaltable"><table class="table">
411 Source File (using SSL)
419 WebSocket, synchronous
424 <a href="../../../example/websocket/server/sync/websocket_server_sync.cpp" target="_top">websocket_server_sync.cpp</a>
429 <a href="../../../example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp" target="_top">websocket_server_sync_ssl.cpp</a>
436 WebSocket, asynchronous
441 <a href="../../../example/websocket/server/async/websocket_server_async.cpp" target="_top">websocket_server_async.cpp</a>
446 <a href="../../../example/websocket/server/async-ssl/websocket_server_async_ssl.cpp" target="_top">websocket_server_async_ssl.cpp</a>
458 <a href="../../../example/websocket/server/coro/websocket_server_coro.cpp" target="_top">websocket_server_coro.cpp</a>
463 <a href="../../../example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp" target="_top">websocket_server_coro_ssl.cpp</a>
470 WebSocket, stackless coroutine
475 <a href="../../../example/websocket/server/stackless/websocket_server_stackless.cpp" target="_top">websocket_server_stackless.cpp</a>
480 <a href="../../../example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp" target="_top">websocket_server_stackless_ssl.cpp</a>
487 WebSocket, fast (suited for benchmarks)
492 <a href="../../../example/websocket/server/fast/websocket_server_fast.cpp" target="_top">websocket_server_fast.cpp</a>
501 <div class="section">
502 <div class="titlepage"><div><div><h3 class="title">
503 <a name="beast.examples.servers_advanced"></a><a class="link" href="examples.html#beast.examples.servers_advanced" title="Servers (Advanced)">Servers (Advanced)</a>
504 </h3></div></div></div>
506 These servers offer both HTTP and WebSocket services on the same port, and
507 illustrate the implementation of advanced features.
509 <div class="informaltable"><table class="table">
540 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
541 <li class="listitem">
544 <li class="listitem">
547 <li class="listitem">
550 <li class="listitem">
551 Parser-oriented HTTP reading
553 <li class="listitem">
554 Dual protocols: HTTP and WebSocket
556 <li class="listitem">
557 Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
563 <a href="../../../example/advanced/server/advanced_server.cpp" target="_top">advanced_server.cpp</a>
570 Advanced, flex (plain + SSL)
574 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
575 <li class="listitem">
578 <li class="listitem">
581 <li class="listitem">
584 <li class="listitem">
585 Parser-oriented HTTP reading
587 <li class="listitem">
588 Dual protocols: HTTP and WebSocket
590 <li class="listitem">
591 Flexible ports: plain and SSL on the same port
593 <li class="listitem">
594 Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
600 <a href="../../../example/advanced/server-flex/advanced_server_flex.cpp" target="_top">advanced_server_flex.cpp</a>
607 Chat Server, multi-threaded
611 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
612 <li class="listitem">
615 <li class="listitem">
616 Broadcasting Messages
618 <li class="listitem">
619 Multi-user Chat Server
621 <li class="listitem">
622 JavaScript Browser Client
624 <li class="listitem">
625 Parser-oriented HTTP reading
627 <li class="listitem">
628 Dual protocols: HTTP and WebSocket
630 <li class="listitem">
631 Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
637 <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
644 <div class="section">
645 <div class="titlepage"><div><div><h3 class="title">
646 <a name="beast.examples.chat_server"></a><a class="link" href="examples.html#beast.examples.chat_server" title="Chat Server 🎦">Chat Server 🎦</a>
647 </h3></div></div></div>
649 This example demonstrates a websocket chat server, allowing multiple users
650 to connect and participate in live, group messaging. It comes with a tiny
651 front end implemented in JavaScript and HTML5 which runs in any browser.
652 The example is accompanied by a one hour presentation which provides a discussion
653 of networking concepts, followed by in-depth explanation of how the client
654 and server are constructed. This talk was delivered at <a href="https://cppcon.org" target="_top">CppCon
655 2018</a>. The source code in the Beast example contains improvements
656 to the original program.
659 <a name="beast.examples.chat_server.chat_websocket_server_and_javasc"></a><p class="title"><b>Table 1.1. Chat WebSocket Server and JavaScript Client</b></p>
660 <div class="table-contents"><table class="table" summary="Chat WebSocket Server and JavaScript Client">
691 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
692 <li class="listitem">
695 <li class="listitem">
698 <li class="listitem">
701 <li class="listitem">
702 Broadcast to multiple peers
704 <li class="listitem">
705 Dual protocols: HTTP and WebSocket
707 <li class="listitem">
708 Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
714 <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
725 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
726 <li class="listitem">
729 <li class="listitem">
732 <li class="listitem">
733 Delivered by the server
735 <li class="listitem">
736 Only 60 lines total including UI
738 <li class="listitem">
739 Completely portable graphics
745 <a href="../../../example/websocket/server/chat-multi/chat_client.html" target="_top">chat_client.html</a>
752 <br class="table-break"><p>
754 <div class="mediaobject"><embed src="https://www.youtube.com/embed/7FQwAjELMek" align="middle" width="560" height="315"></embed></div>
759 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
760 <td align="left"></td>
761 <td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
763 Distributed under the Boost Software License, Version 1.0. (See accompanying
764 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
769 <div class="spirit-nav">
770 <a accesskey="p" href="quick_start/websocket_autobahn_testsuite.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="using_io.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>