Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / beast / doc / html / beast / examples.html
1 <html>
2 <head>
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&#160;1.&#160;Boost.Beast">
8 <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;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">
11 </head>
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>
20 </tr></table>
21 <hr>
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>
24 </div>
25 <div class="section">
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>
29 <p>
30       Source code and build scripts for these programs are located in the <a href="../../../example" target="_top">example</a> directory.
31     </p>
32 <div class="section">
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>
36 <p>
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.
41       </p>
42 <div class="informaltable"><table class="table">
43 <colgroup>
44 <col>
45 <col>
46 <col>
47 </colgroup>
48 <thead><tr>
49 <th>
50                 <p>
51                   Description
52                 </p>
53               </th>
54 <th>
55                 <p>
56                   Source File
57                 </p>
58               </th>
59 <th>
60                 <p>
61                   Source File (using SSL)
62                 </p>
63               </th>
64 </tr></thead>
65 <tbody>
66 <tr>
67 <td>
68                 <p>
69                   HTTP, synchronous
70                 </p>
71               </td>
72 <td>
73                 <p>
74                   <a href="../../../example/http/client/sync/http_client_sync.cpp" target="_top">http_client_sync.cpp</a>
75                 </p>
76               </td>
77 <td>
78                 <p>
79                   <a href="../../../example/http/client/sync-ssl/http_client_sync_ssl.cpp" target="_top">http_client_sync_ssl.cpp</a>
80                 </p>
81               </td>
82 </tr>
83 <tr>
84 <td>
85                 <p>
86                   HTTP, asynchronous
87                 </p>
88               </td>
89 <td>
90                 <p>
91                   <a href="../../../example/http/client/async/http_client_async.cpp" target="_top">http_client_async.cpp</a>
92                 </p>
93               </td>
94 <td>
95                 <p>
96                   <a href="../../../example/http/client/async-ssl/http_client_async_ssl.cpp" target="_top">http_client_async_ssl.cpp</a>
97                 </p>
98               </td>
99 </tr>
100 <tr>
101 <td>
102                 <p>
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>
104                 </p>
105               </td>
106 <td>
107               </td>
108 <td>
109                 <p>
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>
111                 </p>
112               </td>
113 </tr>
114 <tr>
115 <td>
116                 <p>
117                   HTTP, coroutine
118                 </p>
119               </td>
120 <td>
121                 <p>
122                   <a href="../../../example/http/client/coro/http_client_coro.cpp" target="_top">http_client_coro.cpp</a>
123                 </p>
124               </td>
125 <td>
126                 <p>
127                   <a href="../../../example/http/client/coro-ssl/http_client_coro_ssl.cpp" target="_top">http_client_coro_ssl.cpp</a>
128                 </p>
129               </td>
130 </tr>
131 <tr>
132 <td>
133                 <p>
134                   HTTP crawl (asynchronous)
135                 </p>
136               </td>
137 <td>
138                 <p>
139                   <a href="../../../example/http/client/crawl/http_crawl.cpp" target="_top">http_crawl.cpp</a>
140                 </p>
141               </td>
142 <td>
143               </td>
144 </tr>
145 </tbody>
146 </table></div>
147 <p>
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
150         support timeouts.
151       </p>
152 <div class="informaltable"><table class="table">
153 <colgroup>
154 <col>
155 <col>
156 <col>
157 </colgroup>
158 <thead><tr>
159 <th>
160                 <p>
161                   Description
162                 </p>
163               </th>
164 <th>
165                 <p>
166                   Source File
167                 </p>
168               </th>
169 <th>
170                 <p>
171                   Source File (using SSL)
172                 </p>
173               </th>
174 </tr></thead>
175 <tbody>
176 <tr>
177 <td>
178                 <p>
179                   WebSocket, synchronous
180                 </p>
181               </td>
182 <td>
183                 <p>
184                   <a href="../../../example/websocket/client/sync/websocket_client_sync.cpp" target="_top">websocket_client_sync.cpp</a>
185                 </p>
186               </td>
187 <td>
188                 <p>
189                   <a href="../../../example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp" target="_top">websocket_client_sync_ssl.cpp</a>
190                 </p>
191               </td>
192 </tr>
193 <tr>
194 <td>
195                 <p>
196                   WebSocket, asynchronous
197                 </p>
198               </td>
199 <td>
200                 <p>
201                   <a href="../../../example/websocket/client/async/websocket_client_async.cpp" target="_top">websocket_client_async.cpp</a>
202                 </p>
203               </td>
204 <td>
205                 <p>
206                   <a href="../../../example/websocket/client/async-ssl/websocket_client_async_ssl.cpp" target="_top">websocket_client_async_ssl.cpp</a>
207                 </p>
208               </td>
209 </tr>
210 <tr>
211 <td>
212                 <p>
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>
214                 </p>
215               </td>
216 <td>
217               </td>
218 <td>
219                 <p>
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>
221                 </p>
222               </td>
223 </tr>
224 <tr>
225 <td>
226                 <p>
227                   WebSocket, coroutine
228                 </p>
229               </td>
230 <td>
231                 <p>
232                   <a href="../../../example/websocket/client/coro/websocket_client_coro.cpp" target="_top">websocket_client_coro.cpp</a>
233                 </p>
234               </td>
235 <td>
236                 <p>
237                   <a href="../../../example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp" target="_top">websocket_client_coro_ssl.cpp</a>
238                 </p>
239               </td>
240 </tr>
241 </tbody>
242 </table></div>
243 </div>
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>
248 <p>
249         These HTTP servers deliver files from a root directory specified on the command
250         line. All asynchronous servers support timeouts.
251       </p>
252 <div class="informaltable"><table class="table">
253 <colgroup>
254 <col>
255 <col>
256 <col>
257 </colgroup>
258 <thead><tr>
259 <th>
260                 <p>
261                   Description
262                 </p>
263               </th>
264 <th>
265                 <p>
266                   Source File
267                 </p>
268               </th>
269 <th>
270                 <p>
271                   Source File (using SSL)
272                 </p>
273               </th>
274 </tr></thead>
275 <tbody>
276 <tr>
277 <td>
278                 <p>
279                   HTTP, synchronous
280                 </p>
281               </td>
282 <td>
283                 <p>
284                   <a href="../../../example/http/server/sync/http_server_sync.cpp" target="_top">http_server_sync.cpp</a>
285                 </p>
286               </td>
287 <td>
288                 <p>
289                   <a href="../../../example/http/server/sync-ssl/http_server_sync_ssl.cpp" target="_top">http_server_sync_ssl.cpp</a>
290                 </p>
291               </td>
292 </tr>
293 <tr>
294 <td>
295                 <p>
296                   HTTP, asynchronous
297                 </p>
298               </td>
299 <td>
300                 <p>
301                   <a href="../../../example/http/server/async/http_server_async.cpp" target="_top">http_server_async.cpp</a>
302                 </p>
303               </td>
304 <td>
305                 <p>
306                   <a href="../../../example/http/server/async-ssl/http_server_async_ssl.cpp" target="_top">http_server_async_ssl.cpp</a>
307                 </p>
308               </td>
309 </tr>
310 <tr>
311 <td>
312                 <p>
313                   HTTP, coroutine
314                 </p>
315               </td>
316 <td>
317                 <p>
318                   <a href="../../../example/http/server/coro/http_server_coro.cpp" target="_top">http_server_coro.cpp</a>
319                 </p>
320               </td>
321 <td>
322                 <p>
323                   <a href="../../../example/http/server/coro-ssl/http_server_coro_ssl.cpp" target="_top">http_server_coro_ssl.cpp</a>
324                 </p>
325               </td>
326 </tr>
327 <tr>
328 <td>
329                 <p>
330                   HTTP, stackless coroutine
331                 </p>
332               </td>
333 <td>
334                 <p>
335                   <a href="../../../example/http/server/stackless/http_server_stackless.cpp" target="_top">http_server_stackless.cpp</a>
336                 </p>
337               </td>
338 <td>
339                 <p>
340                   <a href="../../../example/http/server/stackless-ssl/http_server_stackless_ssl.cpp" target="_top">http_server_stackless_ssl.cpp</a>
341                 </p>
342               </td>
343 </tr>
344 <tr>
345 <td>
346                 <p>
347                   HTTP, fast (optimized for speed)
348                 </p>
349               </td>
350 <td>
351                 <p>
352                   <a href="../../../example/http/server/fast/http_server_fast.cpp" target="_top">http_server_fast.cpp</a>
353                 </p>
354               </td>
355 <td>
356               </td>
357 </tr>
358 <tr>
359 <td>
360                 <p>
361                   HTTP, small (optimized for space)
362                 </p>
363               </td>
364 <td>
365                 <p>
366                   <a href="../../../example/http/server/small/http_server_small.cpp" target="_top">http_server_small.cpp</a>
367                 </p>
368               </td>
369 <td>
370               </td>
371 </tr>
372 <tr>
373 <td>
374                 <p>
375                   HTTP, flex (plain + SSL)
376                 </p>
377               </td>
378 <td>
379               </td>
380 <td>
381                 <p>
382                   <a href="../../../example/http/server/flex/http_server_flex.cpp" target="_top">http_server_flex.cpp</a>
383                 </p>
384               </td>
385 </tr>
386 </tbody>
387 </table></div>
388 <p>
389         These WebSocket servers echo back any message received, keeping the session
390         open until the client disconnects. All asynchronous servers support timeouts.
391       </p>
392 <div class="informaltable"><table class="table">
393 <colgroup>
394 <col>
395 <col>
396 <col>
397 </colgroup>
398 <thead><tr>
399 <th>
400                 <p>
401                   Description
402                 </p>
403               </th>
404 <th>
405                 <p>
406                   Source File
407                 </p>
408               </th>
409 <th>
410                 <p>
411                   Source File (using SSL)
412                 </p>
413               </th>
414 </tr></thead>
415 <tbody>
416 <tr>
417 <td>
418                 <p>
419                   WebSocket, synchronous
420                 </p>
421               </td>
422 <td>
423                 <p>
424                   <a href="../../../example/websocket/server/sync/websocket_server_sync.cpp" target="_top">websocket_server_sync.cpp</a>
425                 </p>
426               </td>
427 <td>
428                 <p>
429                   <a href="../../../example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp" target="_top">websocket_server_sync_ssl.cpp</a>
430                 </p>
431               </td>
432 </tr>
433 <tr>
434 <td>
435                 <p>
436                   WebSocket, asynchronous
437                 </p>
438               </td>
439 <td>
440                 <p>
441                   <a href="../../../example/websocket/server/async/websocket_server_async.cpp" target="_top">websocket_server_async.cpp</a>
442                 </p>
443               </td>
444 <td>
445                 <p>
446                   <a href="../../../example/websocket/server/async-ssl/websocket_server_async_ssl.cpp" target="_top">websocket_server_async_ssl.cpp</a>
447                 </p>
448               </td>
449 </tr>
450 <tr>
451 <td>
452                 <p>
453                   WebSocket, coroutine
454                 </p>
455               </td>
456 <td>
457                 <p>
458                   <a href="../../../example/websocket/server/coro/websocket_server_coro.cpp" target="_top">websocket_server_coro.cpp</a>
459                 </p>
460               </td>
461 <td>
462                 <p>
463                   <a href="../../../example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp" target="_top">websocket_server_coro_ssl.cpp</a>
464                 </p>
465               </td>
466 </tr>
467 <tr>
468 <td>
469                 <p>
470                   WebSocket, stackless coroutine
471                 </p>
472               </td>
473 <td>
474                 <p>
475                   <a href="../../../example/websocket/server/stackless/websocket_server_stackless.cpp" target="_top">websocket_server_stackless.cpp</a>
476                 </p>
477               </td>
478 <td>
479                 <p>
480                   <a href="../../../example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp" target="_top">websocket_server_stackless_ssl.cpp</a>
481                 </p>
482               </td>
483 </tr>
484 <tr>
485 <td>
486                 <p>
487                   WebSocket, fast (suited for benchmarks)
488                 </p>
489               </td>
490 <td>
491                 <p>
492                   <a href="../../../example/websocket/server/fast/websocket_server_fast.cpp" target="_top">websocket_server_fast.cpp</a>
493                 </p>
494               </td>
495 <td>
496               </td>
497 </tr>
498 </tbody>
499 </table></div>
500 </div>
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>
505 <p>
506         These servers offer both HTTP and WebSocket services on the same port, and
507         illustrate the implementation of advanced features.
508       </p>
509 <div class="informaltable"><table class="table">
510 <colgroup>
511 <col>
512 <col>
513 <col>
514 </colgroup>
515 <thead><tr>
516 <th>
517                 <p>
518                   Description
519                 </p>
520               </th>
521 <th>
522                 <p>
523                   Features
524                 </p>
525               </th>
526 <th>
527                 <p>
528                   Sources
529                 </p>
530               </th>
531 </tr></thead>
532 <tbody>
533 <tr>
534 <td>
535                 <p>
536                   Advanced
537                 </p>
538               </td>
539 <td>
540                 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
541 <li class="listitem">
542                       Timeouts
543                     </li>
544 <li class="listitem">
545                       Multi-threaded
546                     </li>
547 <li class="listitem">
548                       HTTP pipelining
549                     </li>
550 <li class="listitem">
551                       Parser-oriented HTTP reading
552                     </li>
553 <li class="listitem">
554                       Dual protocols: HTTP and WebSocket
555                     </li>
556 <li class="listitem">
557                       Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
558                     </li>
559 </ul></div>
560               </td>
561 <td>
562                 <p>
563                   <a href="../../../example/advanced/server/advanced_server.cpp" target="_top">advanced_server.cpp</a>
564                 </p>
565               </td>
566 </tr>
567 <tr>
568 <td>
569                 <p>
570                   Advanced, flex (plain + SSL)
571                 </p>
572               </td>
573 <td>
574                 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
575 <li class="listitem">
576                       Timeouts
577                     </li>
578 <li class="listitem">
579                       Multi-threaded
580                     </li>
581 <li class="listitem">
582                       HTTP pipelining
583                     </li>
584 <li class="listitem">
585                       Parser-oriented HTTP reading
586                     </li>
587 <li class="listitem">
588                       Dual protocols: HTTP and WebSocket
589                     </li>
590 <li class="listitem">
591                       Flexible ports: plain and SSL on the same port
592                     </li>
593 <li class="listitem">
594                       Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
595                     </li>
596 </ul></div>
597               </td>
598 <td>
599                 <p>
600                   <a href="../../../example/advanced/server-flex/advanced_server_flex.cpp" target="_top">advanced_server_flex.cpp</a>
601                 </p>
602               </td>
603 </tr>
604 <tr>
605 <td>
606                 <p>
607                   Chat Server, multi-threaded
608                 </p>
609               </td>
610 <td>
611                 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
612 <li class="listitem">
613                       Multi-threaded
614                     </li>
615 <li class="listitem">
616                       Broadcasting Messages
617                     </li>
618 <li class="listitem">
619                       Multi-user Chat Server
620                     </li>
621 <li class="listitem">
622                       JavaScript Browser Client
623                     </li>
624 <li class="listitem">
625                       Parser-oriented HTTP reading
626                     </li>
627 <li class="listitem">
628                       Dual protocols: HTTP and WebSocket
629                     </li>
630 <li class="listitem">
631                       Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
632                     </li>
633 </ul></div>
634               </td>
635 <td>
636                 <p>
637                   <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
638                 </p>
639               </td>
640 </tr>
641 </tbody>
642 </table></div>
643 </div>
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 &#127910;">Chat Server &#127910;</a>
647 </h3></div></div></div>
648 <p>
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.
657       </p>
658 <div class="table">
659 <a name="beast.examples.chat_server.chat_websocket_server_and_javasc"></a><p class="title"><b>Table&#160;1.1.&#160;Chat WebSocket Server and JavaScript Client</b></p>
660 <div class="table-contents"><table class="table" summary="Chat WebSocket Server and JavaScript Client">
661 <colgroup>
662 <col>
663 <col>
664 <col>
665 </colgroup>
666 <thead><tr>
667 <th>
668                 <p>
669                   Component
670                 </p>
671               </th>
672 <th>
673                 <p>
674                   Features
675                 </p>
676               </th>
677 <th>
678                 <p>
679                   Sources
680                 </p>
681               </th>
682 </tr></thead>
683 <tbody>
684 <tr>
685 <td>
686                 <p>
687                   Server
688                 </p>
689               </td>
690 <td>
691                 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
692 <li class="listitem">
693                       C++
694                     </li>
695 <li class="listitem">
696                       Timeouts
697                     </li>
698 <li class="listitem">
699                       Multi-threaded
700                     </li>
701 <li class="listitem">
702                       Broadcast to multiple peers
703                     </li>
704 <li class="listitem">
705                       Dual protocols: HTTP and WebSocket
706                     </li>
707 <li class="listitem">
708                       Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
709                     </li>
710 </ul></div>
711               </td>
712 <td>
713                 <p>
714                   <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
715                 </p>
716               </td>
717 </tr>
718 <tr>
719 <td>
720                 <p>
721                   Client
722                 </p>
723               </td>
724 <td>
725                 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
726 <li class="listitem">
727                       JavaScript / HTML5
728                     </li>
729 <li class="listitem">
730                       Runs in the browser
731                     </li>
732 <li class="listitem">
733                       Delivered by the server
734                     </li>
735 <li class="listitem">
736                       Only 60 lines total including UI
737                     </li>
738 <li class="listitem">
739                       Completely portable graphics
740                     </li>
741 </ul></div>
742               </td>
743 <td>
744                 <p>
745                   <a href="../../../example/websocket/server/chat-multi/chat_client.html" target="_top">chat_client.html</a>
746                 </p>
747               </td>
748 </tr>
749 </tbody>
750 </table></div>
751 </div>
752 <br class="table-break"><p>
753         </p>
754 <div class="mediaobject"><embed src="https://www.youtube.com/embed/7FQwAjELMek" align="middle" width="560" height="315"></embed></div>
755 <p>
756       </p>
757 </div>
758 </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 &#169; 2016-2019 Vinnie
762       Falco<p>
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>)
765       </p>
766 </div></td>
767 </tr></table>
768 <hr>
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>
771 </div>
772 </body>
773 </html>