1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>C++11 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="../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../examples.html" title="Examples"> 9<link rel="prev" href="cpp03_examples.html" title="C++03 Examples"> 10<link rel="next" href="cpp14_examples.html" title="C++14 Examples"> 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="cpp03_examples.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../examples.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cpp14_examples.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.examples.cpp11_examples"></a><a class="link" href="cpp11_examples.html" title="C++11 Examples">C++11 Examples</a> 28</h3></div></div></div> 29<h5> 30<a name="boost_asio.examples.cpp11_examples.h0"></a> 31 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.allocation"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.allocation">Allocation</a> 32 </h5> 33<p> 34 This example shows how to customise the allocation of memory associated with 35 asynchronous operations. 36 </p> 37<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 38 <a href="../example/cpp11/allocation/server.cpp" target="_top">boost_asio/example/cpp11/allocation/server.cpp</a> 39 </li></ul></div> 40<h5> 41<a name="boost_asio.examples.cpp11_examples.h1"></a> 42 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.buffers"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.buffers">Buffers</a> 43 </h5> 44<p> 45 This example demonstrates how to create reference counted buffers that can 46 be used with socket read and write operations. 47 </p> 48<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 49 <a href="../example/cpp11/buffers/reference_counted.cpp" target="_top">boost_asio/example/cpp11/buffers/reference_counted.cpp</a> 50 </li></ul></div> 51<h5> 52<a name="boost_asio.examples.cpp11_examples.h2"></a> 53 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.chat"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.chat">Chat</a> 54 </h5> 55<p> 56 This example implements a chat server and client. The programs use a custom 57 protocol with a fixed length message header and variable length message body. 58 </p> 59<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 60<li class="listitem"> 61 <a href="../example/cpp11/chat/chat_message.hpp" target="_top">boost_asio/example/cpp11/chat/chat_message.hpp</a> 62 </li> 63<li class="listitem"> 64 <a href="../example/cpp11/chat/chat_client.cpp" target="_top">boost_asio/example/cpp11/chat/chat_client.cpp</a> 65 </li> 66<li class="listitem"> 67 <a href="../example/cpp11/chat/chat_server.cpp" target="_top">boost_asio/example/cpp11/chat/chat_server.cpp</a> 68 </li> 69</ul></div> 70<h5> 71<a name="boost_asio.examples.cpp11_examples.h3"></a> 72 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.echo"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.echo">Echo</a> 73 </h5> 74<p> 75 A collection of simple clients and servers, showing the use of both synchronous 76 and asynchronous operations. 77 </p> 78<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 79<li class="listitem"> 80 <a href="../example/cpp11/echo/async_tcp_echo_server.cpp" target="_top">boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp</a> 81 </li> 82<li class="listitem"> 83 <a href="../example/cpp11/echo/async_udp_echo_server.cpp" target="_top">boost_asio/example/cpp11/echo/async_udp_echo_server.cpp</a> 84 </li> 85<li class="listitem"> 86 <a href="../example/cpp11/echo/blocking_tcp_echo_client.cpp" target="_top">boost_asio/example/cpp11/echo/blocking_tcp_echo_client.cpp</a> 87 </li> 88<li class="listitem"> 89 <a href="../example/cpp11/echo/blocking_tcp_echo_server.cpp" target="_top">boost_asio/example/cpp11/echo/blocking_tcp_echo_server.cpp</a> 90 </li> 91<li class="listitem"> 92 <a href="../example/cpp11/echo/blocking_udp_echo_client.cpp" target="_top">boost_asio/example/cpp11/echo/blocking_udp_echo_client.cpp</a> 93 </li> 94<li class="listitem"> 95 <a href="../example/cpp11/echo/blocking_udp_echo_server.cpp" target="_top">boost_asio/example/cpp11/echo/blocking_udp_echo_server.cpp</a> 96 </li> 97</ul></div> 98<h5> 99<a name="boost_asio.examples.cpp11_examples.h4"></a> 100 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.fork"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.fork">Fork</a> 101 </h5> 102<p> 103 These POSIX-specific examples show how to use Boost.Asio in conjunction with 104 the <code class="computeroutput">fork()</code> system call. The first example illustrates the steps 105 required to start a daemon process: 106 </p> 107<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 108 <a href="../example/cpp11/fork/daemon.cpp" target="_top">boost_asio/example/cpp11/fork/daemon.cpp</a> 109 </li></ul></div> 110<p> 111 The second example demonstrates how it is possible to fork a process from 112 within a completion handler. 113 </p> 114<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 115 <a href="../example/cpp11/fork/process_per_connection.cpp" target="_top">boost_asio/example/cpp11/fork/process_per_connection.cpp</a> 116 </li></ul></div> 117<h5> 118<a name="boost_asio.examples.cpp11_examples.h5"></a> 119 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.futures"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.futures">Futures</a> 120 </h5> 121<p> 122 This example demonstrates how to use std::future in conjunction with Boost.Asio's 123 asynchronous operations. 124 </p> 125<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 126 <a href="../example/cpp11/futures/daytime_client.cpp" target="_top">boost_asio/example/cpp11/futures/daytime_client.cpp</a> 127 </li></ul></div> 128<h5> 129<a name="boost_asio.examples.cpp11_examples.h6"></a> 130 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.handler_tracking"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.handler_tracking">Handler 131 Tracking</a> 132 </h5> 133<p> 134 This example header file shows how to implement custom handler tracking. 135 </p> 136<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 137 <a href="../example/cpp11/handler_tracking/custom_tracking.hpp" target="_top">boost_asio/example/cpp11/handler_tracking/custom_tracking.hpp</a> 138 </li></ul></div> 139<p> 140 This example program shows how to include source location information in 141 the handler tracking output. 142 </p> 143<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 144 <a href="../example/cpp11/handler_tracking/async_tcp_echo_server.cpp" target="_top">boost_asio/example/cpp11/handler_tracking/async_tcp_echo_server.cpp</a> 145 </li></ul></div> 146<h5> 147<a name="boost_asio.examples.cpp11_examples.h7"></a> 148 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.http_server"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.http_server">HTTP 149 Server</a> 150 </h5> 151<p> 152 This example illustrates the use of asio in a simple single-threaded server 153 implementation of HTTP 1.0. It demonstrates how to perform a clean shutdown 154 by cancelling all outstanding asynchronous operations. 155 </p> 156<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 157<li class="listitem"> 158 <a href="../example/cpp11/http/server/connection.cpp" target="_top">boost_asio/example/cpp11/http/server/connection.cpp</a> 159 </li> 160<li class="listitem"> 161 <a href="../example/cpp11/http/server/connection.hpp" target="_top">boost_asio/example/cpp11/http/server/connection.hpp</a> 162 </li> 163<li class="listitem"> 164 <a href="../example/cpp11/http/server/connection_manager.cpp" target="_top">boost_asio/example/cpp11/http/server/connection_manager.cpp</a> 165 </li> 166<li class="listitem"> 167 <a href="../example/cpp11/http/server/connection_manager.hpp" target="_top">boost_asio/example/cpp11/http/server/connection_manager.hpp</a> 168 </li> 169<li class="listitem"> 170 <a href="../example/cpp11/http/server/header.hpp" target="_top">boost_asio/example/cpp11/http/server/header.hpp</a> 171 </li> 172<li class="listitem"> 173 <a href="../example/cpp11/http/server/main.cpp" target="_top">boost_asio/example/cpp11/http/server/main.cpp</a> 174 </li> 175<li class="listitem"> 176 <a href="../example/cpp11/http/server/mime_types.cpp" target="_top">boost_asio/example/cpp11/http/server/mime_types.cpp</a> 177 </li> 178<li class="listitem"> 179 <a href="../example/cpp11/http/server/mime_types.hpp" target="_top">boost_asio/example/cpp11/http/server/mime_types.hpp</a> 180 </li> 181<li class="listitem"> 182 <a href="../example/cpp11/http/server/reply.cpp" target="_top">boost_asio/example/cpp11/http/server/reply.cpp</a> 183 </li> 184<li class="listitem"> 185 <a href="../example/cpp11/http/server/reply.hpp" target="_top">boost_asio/example/cpp11/http/server/reply.hpp</a> 186 </li> 187<li class="listitem"> 188 <a href="../example/cpp11/http/server/request.hpp" target="_top">boost_asio/example/cpp11/http/server/request.hpp</a> 189 </li> 190<li class="listitem"> 191 <a href="../example/cpp11/http/server/request_handler.cpp" target="_top">boost_asio/example/cpp11/http/server/request_handler.cpp</a> 192 </li> 193<li class="listitem"> 194 <a href="../example/cpp11/http/server/request_handler.hpp" target="_top">boost_asio/example/cpp11/http/server/request_handler.hpp</a> 195 </li> 196<li class="listitem"> 197 <a href="../example/cpp11/http/server/request_parser.cpp" target="_top">boost_asio/example/cpp11/http/server/request_parser.cpp</a> 198 </li> 199<li class="listitem"> 200 <a href="../example/cpp11/http/server/request_parser.hpp" target="_top">boost_asio/example/cpp11/http/server/request_parser.hpp</a> 201 </li> 202<li class="listitem"> 203 <a href="../example/cpp11/http/server/server.cpp" target="_top">boost_asio/example/cpp11/http/server/server.cpp</a> 204 </li> 205<li class="listitem"> 206 <a href="../example/cpp11/http/server/server.hpp" target="_top">boost_asio/example/cpp11/http/server/server.hpp</a> 207 </li> 208</ul></div> 209<h5> 210<a name="boost_asio.examples.cpp11_examples.h8"></a> 211 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.multicast"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.multicast">Multicast</a> 212 </h5> 213<p> 214 An example showing the use of multicast to transmit packets to a group of 215 subscribers. 216 </p> 217<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 218<li class="listitem"> 219 <a href="../example/cpp11/multicast/receiver.cpp" target="_top">boost_asio/example/cpp11/multicast/receiver.cpp</a> 220 </li> 221<li class="listitem"> 222 <a href="../example/cpp11/multicast/sender.cpp" target="_top">boost_asio/example/cpp11/multicast/sender.cpp</a> 223 </li> 224</ul></div> 225<h5> 226<a name="boost_asio.examples.cpp11_examples.h9"></a> 227 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.nonblocking"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.nonblocking">Nonblocking</a> 228 </h5> 229<p> 230 Example demonstrating reactor-style operations for integrating a third-party 231 library that wants to perform the I/O operations itself. 232 </p> 233<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 234 <a href="../example/cpp11/nonblocking/third_party_lib.cpp" target="_top">boost_asio/example/cpp11/nonblocking/third_party_lib.cpp</a> 235 </li></ul></div> 236<h5> 237<a name="boost_asio.examples.cpp11_examples.h10"></a> 238 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.operations"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.operations">Operations</a> 239 </h5> 240<p> 241 Examples showing how to implement composed asynchronous operations as reusable 242 library functions. 243 </p> 244<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 245<li class="listitem"> 246 <a href="../example/cpp11/operations/composed_1.cpp" target="_top">boost_asio/example/cpp11/operations/composed_1.cpp</a> 247 </li> 248<li class="listitem"> 249 <a href="../example/cpp11/operations/composed_2.cpp" target="_top">boost_asio/example/cpp11/operations/composed_2.cpp</a> 250 </li> 251<li class="listitem"> 252 <a href="../example/cpp11/operations/composed_3.cpp" target="_top">boost_asio/example/cpp11/operations/composed_3.cpp</a> 253 </li> 254<li class="listitem"> 255 <a href="../example/cpp11/operations/composed_4.cpp" target="_top">boost_asio/example/cpp11/operations/composed_4.cpp</a> 256 </li> 257<li class="listitem"> 258 <a href="../example/cpp11/operations/composed_5.cpp" target="_top">boost_asio/example/cpp11/operations/composed_5.cpp</a> 259 </li> 260<li class="listitem"> 261 <a href="../example/cpp11/operations/composed_6.cpp" target="_top">boost_asio/example/cpp11/operations/composed_6.cpp</a> 262 </li> 263<li class="listitem"> 264 <a href="../example/cpp11/operations/composed_7.cpp" target="_top">boost_asio/example/cpp11/operations/composed_7.cpp</a> 265 </li> 266<li class="listitem"> 267 <a href="../example/cpp11/operations/composed_8.cpp" target="_top">boost_asio/example/cpp11/operations/composed_8.cpp</a> 268 </li> 269</ul></div> 270<h5> 271<a name="boost_asio.examples.cpp11_examples.h11"></a> 272 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.socks_4"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.socks_4">SOCKS 273 4</a> 274 </h5> 275<p> 276 Example client program implementing the SOCKS 4 protocol for communication 277 via a proxy. 278 </p> 279<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 280<li class="listitem"> 281 <a href="../example/cpp11/socks4/sync_client.cpp" target="_top">boost_asio/example/cpp11/socks4/sync_client.cpp</a> 282 </li> 283<li class="listitem"> 284 <a href="../example/cpp11/socks4/socks4.hpp" target="_top">boost_asio/example/cpp11/socks4/socks4.hpp</a> 285 </li> 286</ul></div> 287<h5> 288<a name="boost_asio.examples.cpp11_examples.h12"></a> 289 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.spawn"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.spawn">Spawn</a> 290 </h5> 291<p> 292 Example of using the boost::asio::spawn() function, a wrapper around the 293 <a href="http://www.boost.org/doc/libs/release/libs/coroutine/index.html" target="_top">Boost.Coroutine</a> 294 library, to implement a chain of asynchronous operations using stackful coroutines. 295 </p> 296<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 297 <a href="../example/cpp11/spawn/echo_server.cpp" target="_top">boost_asio/example/cpp11/spawn/echo_server.cpp</a> 298 </li></ul></div> 299<h5> 300<a name="boost_asio.examples.cpp11_examples.h13"></a> 301 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.ssl"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.ssl">SSL</a> 302 </h5> 303<p> 304 Example client and server programs showing the use of the <a class="link" href="../reference/ssl__stream.html" title="ssl::stream">ssl::stream<></a> 305 template with asynchronous operations. 306 </p> 307<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 308<li class="listitem"> 309 <a href="../example/cpp11/ssl/client.cpp" target="_top">boost_asio/example/cpp11/ssl/client.cpp</a> 310 </li> 311<li class="listitem"> 312 <a href="../example/cpp11/ssl/server.cpp" target="_top">boost_asio/example/cpp11/ssl/server.cpp</a> 313 </li> 314</ul></div> 315<h5> 316<a name="boost_asio.examples.cpp11_examples.h14"></a> 317 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.timeouts"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.timeouts">Timeouts</a> 318 </h5> 319<p> 320 A collection of examples showing how to cancel long running asynchronous 321 operations after a period of time. 322 </p> 323<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 324<li class="listitem"> 325 <a href="../example/cpp11/timeouts/async_tcp_client.cpp" target="_top">boost_asio/example/cpp11/timeouts/async_tcp_client.cpp</a> 326 </li> 327<li class="listitem"> 328 <a href="../example/cpp11/timeouts/blocking_tcp_client.cpp" target="_top">boost_asio/example/cpp11/timeouts/blocking_tcp_client.cpp</a> 329 </li> 330<li class="listitem"> 331 <a href="../example/cpp11/timeouts/blocking_token_tcp_client.cpp" target="_top">boost_asio/example/cpp11/timeouts/blocking_token_tcp_client.cpp</a> 332 </li> 333<li class="listitem"> 334 <a href="../example/cpp11/timeouts/blocking_udp_client.cpp" target="_top">boost_asio/example/cpp11/timeouts/blocking_udp_client.cpp</a> 335 </li> 336<li class="listitem"> 337 <a href="../example/cpp11/timeouts/server.cpp" target="_top">boost_asio/example/cpp11/timeouts/server.cpp</a> 338 </li> 339</ul></div> 340<h5> 341<a name="boost_asio.examples.cpp11_examples.h15"></a> 342 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.timers"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.timers">Timers</a> 343 </h5> 344<p> 345 Example showing how to customise basic_waitable_timer using a different clock 346 type. 347 </p> 348<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 349 <a href="../example/cpp11/timers/time_t_timer.cpp" target="_top">boost_asio/example/cpp11/timers/time_t_timer.cpp</a> 350 </li></ul></div> 351<h5> 352<a name="boost_asio.examples.cpp11_examples.h16"></a> 353 <span class="phrase"><a name="boost_asio.examples.cpp11_examples.unix_domain_sockets"></a></span><a class="link" href="cpp11_examples.html#boost_asio.examples.cpp11_examples.unix_domain_sockets">UNIX Domain 354 Sockets</a> 355 </h5> 356<p> 357 Examples showing how to use UNIX domain (local) sockets. 358 </p> 359<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 360<li class="listitem"> 361 <a href="../example/cpp11/local/connect_pair.cpp" target="_top">boost_asio/example/cpp11/local/connect_pair.cpp</a> 362 </li> 363<li class="listitem"> 364 <a href="../example/cpp11/local/iostream_client.cpp" target="_top">boost_asio/example/cpp11/local/iostream_client.cpp</a> 365 </li> 366<li class="listitem"> 367 <a href="../example/cpp11/local/stream_server.cpp" target="_top">boost_asio/example/cpp11/local/stream_server.cpp</a> 368 </li> 369<li class="listitem"> 370 <a href="../example/cpp11/local/stream_client.cpp" target="_top">boost_asio/example/cpp11/local/stream_client.cpp</a> 371 </li> 372</ul></div> 373</div> 374<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 375<td align="left"></td> 376<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 377 Kohlhoff<p> 378 Distributed under the Boost Software License, Version 1.0. (See accompanying 379 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>) 380 </p> 381</div></td> 382</tr></table> 383<hr> 384<div class="spirit-nav"> 385<a accesskey="p" href="cpp03_examples.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../examples.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cpp14_examples.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 386</div> 387</body> 388</html> 389