[/
 / Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]

[section:examples Examples]


* [link boost_asio.examples.cpp11_examples C++11 Examples]: Illustrates the use of
Boost.Asio using only C++11 language and library features. Where necessary, the
examples make use of selected Boost C++ libraries.

* [link boost_asio.examples.cpp14_examples C++14 Examples]: Contains a limited set of
the C++03 Boost.Asio examples, updated to use only C++14 library and language
facilities. These examples do not make direct use of Boost C++ libraries.

* [link boost_asio.examples.cpp17_examples C++17 Examples]: Selected examples
illustrating C++17 usage in conjunction with Technical Specifications.

* [link boost_asio.examples.cpp20_examples C++20 Examples]: Selected examples
using C++20 language features.


[section:cpp11_examples C++11 Examples]


[heading Allocation]

This example shows how to customise the allocation of memory associated with
asynchronous operations.

* [@boost_asio/example/cpp11/allocation/server.cpp]


[heading Buffers]

This example demonstrates how to create reference counted buffers that can be
used with socket read and write operations.

* [@boost_asio/example/cpp11/buffers/reference_counted.cpp]


[heading Chat]

This example implements a chat server and client. The programs use a custom
protocol with a fixed length message header and variable length message body.

* [@boost_asio/example/cpp11/chat/chat_message.hpp]
* [@boost_asio/example/cpp11/chat/chat_client.cpp]
* [@boost_asio/example/cpp11/chat/chat_server.cpp]

The following POSIX-specific chat client demonstrates how to use the
[link boost_asio.reference.posix__stream_descriptor posix::stream_descriptor] class to
perform console input and output.

* [@boost_asio/example/cpp11/chat/posix_chat_client.cpp]


[heading Deferred]

Examples showing how to use the [link boost_asio.reference.deferred `deferred`]
completion token.

* [@boost_asio/example/cpp11/deferred/deferred_1.cpp]
* [@boost_asio/example/cpp11/deferred/deferred_2.cpp]


[heading Echo]

A collection of simple clients and servers, showing the use of both synchronous
and asynchronous operations.

* [@boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp]
* [@boost_asio/example/cpp11/echo/async_udp_echo_server.cpp]
* [@boost_asio/example/cpp11/echo/blocking_tcp_echo_client.cpp]
* [@boost_asio/example/cpp11/echo/blocking_tcp_echo_server.cpp]
* [@boost_asio/example/cpp11/echo/blocking_udp_echo_client.cpp]
* [@boost_asio/example/cpp11/echo/blocking_udp_echo_server.cpp]


[heading Fork]

These POSIX-specific examples show how to use Boost.Asio in conjunction with the
`fork()` system call. The first example illustrates the steps required to start
a daemon process:

* [@boost_asio/example/cpp11/fork/daemon.cpp]

The second example demonstrates how it is possible to fork a process from
within a completion handler.

* [@boost_asio/example/cpp11/fork/process_per_connection.cpp]


[heading Futures]

This example demonstrates how to use std::future in conjunction with
Boost.Asio's asynchronous operations.

* [@boost_asio/example/cpp11/futures/daytime_client.cpp]


[heading Handler Tracking]

This example header file shows how to implement custom handler tracking.

* [@boost_asio/example/cpp11/handler_tracking/custom_tracking.hpp]

This example program shows how to include source location information in
the handler tracking output.

* [@boost_asio/example/cpp11/handler_tracking/async_tcp_echo_server.cpp]


[heading HTTP Client]

Example programs implementing simple HTTP 1.0 clients. These examples show how
to use the [link boost_asio.reference.read_until read_until] and [link
boost_asio.reference.async_read_until async_read_until] functions.

* [@boost_asio/example/cpp11/http/client/sync_client.cpp]
* [@boost_asio/example/cpp11/http/client/async_client.cpp]


[heading HTTP Server]

This example illustrates the use of asio in a simple single-threaded server
implementation of HTTP 1.0. It demonstrates how to perform a clean shutdown by
cancelling all outstanding asynchronous operations.

* [@boost_asio/example/cpp11/http/server/connection.cpp]
* [@boost_asio/example/cpp11/http/server/connection.hpp]
* [@boost_asio/example/cpp11/http/server/connection_manager.cpp]
* [@boost_asio/example/cpp11/http/server/connection_manager.hpp]
* [@boost_asio/example/cpp11/http/server/header.hpp]
* [@boost_asio/example/cpp11/http/server/main.cpp]
* [@boost_asio/example/cpp11/http/server/mime_types.cpp]
* [@boost_asio/example/cpp11/http/server/mime_types.hpp]
* [@boost_asio/example/cpp11/http/server/reply.cpp]
* [@boost_asio/example/cpp11/http/server/reply.hpp]
* [@boost_asio/example/cpp11/http/server/request.hpp]
* [@boost_asio/example/cpp11/http/server/request_handler.cpp]
* [@boost_asio/example/cpp11/http/server/request_handler.hpp]
* [@boost_asio/example/cpp11/http/server/request_parser.cpp]
* [@boost_asio/example/cpp11/http/server/request_parser.hpp]
* [@boost_asio/example/cpp11/http/server/server.cpp]
* [@boost_asio/example/cpp11/http/server/server.hpp]


[heading HTTP Server 2]

An HTTP server using an io_context-per-CPU design.

* [@boost_asio/example/cpp11/http/server2/connection.cpp]
* [@boost_asio/example/cpp11/http/server2/connection.hpp]
* [@boost_asio/example/cpp11/http/server2/header.hpp]
* [@boost_asio/example/cpp11/http/server2/io_context_pool.cpp]
* [@boost_asio/example/cpp11/http/server2/io_context_pool.hpp]
* [@boost_asio/example/cpp11/http/server2/main.cpp]
* [@boost_asio/example/cpp11/http/server2/mime_types.cpp]
* [@boost_asio/example/cpp11/http/server2/mime_types.hpp]
* [@boost_asio/example/cpp11/http/server2/reply.cpp]
* [@boost_asio/example/cpp11/http/server2/reply.hpp]
* [@boost_asio/example/cpp11/http/server2/request.hpp]
* [@boost_asio/example/cpp11/http/server2/request_handler.cpp]
* [@boost_asio/example/cpp11/http/server2/request_handler.hpp]
* [@boost_asio/example/cpp11/http/server2/request_parser.cpp]
* [@boost_asio/example/cpp11/http/server2/request_parser.hpp]
* [@boost_asio/example/cpp11/http/server2/server.cpp]
* [@boost_asio/example/cpp11/http/server2/server.hpp]


[heading HTTP Server 3]

An HTTP server using a single io_context and a thread pool calling `io_context::run()`.

* [@boost_asio/example/cpp11/http/server3/connection.cpp]
* [@boost_asio/example/cpp11/http/server3/connection.hpp]
* [@boost_asio/example/cpp11/http/server3/header.hpp]
* [@boost_asio/example/cpp11/http/server3/main.cpp]
* [@boost_asio/example/cpp11/http/server3/mime_types.cpp]
* [@boost_asio/example/cpp11/http/server3/mime_types.hpp]
* [@boost_asio/example/cpp11/http/server3/reply.cpp]
* [@boost_asio/example/cpp11/http/server3/reply.hpp]
* [@boost_asio/example/cpp11/http/server3/request.hpp]
* [@boost_asio/example/cpp11/http/server3/request_handler.cpp]
* [@boost_asio/example/cpp11/http/server3/request_handler.hpp]
* [@boost_asio/example/cpp11/http/server3/request_parser.cpp]
* [@boost_asio/example/cpp11/http/server3/request_parser.hpp]
* [@boost_asio/example/cpp11/http/server3/server.cpp]
* [@boost_asio/example/cpp11/http/server3/server.hpp]


[heading HTTP Server 4]

A single-threaded HTTP server implemented using stackless coroutines.

* [@boost_asio/example/cpp11/http/server4/file_handler.cpp]
* [@boost_asio/example/cpp11/http/server4/file_handler.hpp]
* [@boost_asio/example/cpp11/http/server4/header.hpp]
* [@boost_asio/example/cpp11/http/server4/main.cpp]
* [@boost_asio/example/cpp11/http/server4/mime_types.cpp]
* [@boost_asio/example/cpp11/http/server4/mime_types.hpp]
* [@boost_asio/example/cpp11/http/server4/reply.cpp]
* [@boost_asio/example/cpp11/http/server4/reply.hpp]
* [@boost_asio/example/cpp11/http/server4/request.hpp]
* [@boost_asio/example/cpp11/http/server4/request_parser.cpp]
* [@boost_asio/example/cpp11/http/server4/request_parser.hpp]
* [@boost_asio/example/cpp11/http/server4/server.cpp]
* [@boost_asio/example/cpp11/http/server4/server.hpp]


[heading ICMP]

This example shows how to use raw sockets with ICMP to ping a remote host.

* [@boost_asio/example/cpp11/icmp/ping.cpp]
* [@boost_asio/example/cpp11/icmp/ipv4_header.hpp]
* [@boost_asio/example/cpp11/icmp/icmp_header.hpp]


[heading Invocation]

This example shows how to customise handler invocation. Completion handlers are
added to a priority queue rather than executed immediately.

* [@boost_asio/example/cpp11/invocation/prioritised_handlers.cpp]


[heading Iostreams]

Two examples showing how to use [link boost_asio.reference.ip__tcp.iostream
ip::tcp::iostream].

* [@boost_asio/example/cpp11/iostreams/daytime_client.cpp]
* [@boost_asio/example/cpp11/iostreams/daytime_server.cpp]
* [@boost_asio/example/cpp11/iostreams/http_client.cpp]


[heading Multicast]

An example showing the use of multicast to transmit packets to a group of
subscribers.

* [@boost_asio/example/cpp11/multicast/receiver.cpp]
* [@boost_asio/example/cpp11/multicast/sender.cpp]


[heading Nonblocking]

Example demonstrating reactor-style operations for integrating a third-party
library that wants to perform the I/O operations itself.

* [@boost_asio/example/cpp11/nonblocking/third_party_lib.cpp]


[heading Operations]

Examples showing how to implement composed asynchronous operations as reusable library functions.

* [@boost_asio/example/cpp11/operations/composed_1.cpp]
* [@boost_asio/example/cpp11/operations/composed_2.cpp]
* [@boost_asio/example/cpp11/operations/composed_3.cpp]
* [@boost_asio/example/cpp11/operations/composed_4.cpp]
* [@boost_asio/example/cpp11/operations/composed_5.cpp]
* [@boost_asio/example/cpp11/operations/composed_6.cpp]
* [@boost_asio/example/cpp11/operations/composed_7.cpp]
* [@boost_asio/example/cpp11/operations/composed_8.cpp]


[heading Parallel Groups]

Examples showing how to use the [link
boost_asio.reference.experimental__make_parallel_group
`experimental::make_parallel_group`] operation.

* [@boost_asio/example/cpp11/parallel_group/wait_for_all.cpp]
* [@boost_asio/example/cpp11/parallel_group/wait_for_one.cpp]
* [@boost_asio/example/cpp11/parallel_group/wait_for_one_error.cpp]
* [@boost_asio/example/cpp11/parallel_group/wait_for_one_success.cpp]
* [@boost_asio/example/cpp11/parallel_group/ranged_wait_for_all.cpp]


[heading Porthopper]

Example illustrating mixed synchronous and asynchronous operations.

* [@boost_asio/example/cpp11/porthopper/protocol.hpp]
* [@boost_asio/example/cpp11/porthopper/client.cpp]
* [@boost_asio/example/cpp11/porthopper/server.cpp]


[heading Serialization]

This example shows how Boost.Serialization can be used with asio to encode and
decode structures for transmission over a socket.

* [@boost_asio/example/cpp11/serialization/client.cpp]
* [@boost_asio/example/cpp11/serialization/connection.hpp]
* [@boost_asio/example/cpp11/serialization/server.cpp]
* [@boost_asio/example/cpp11/serialization/stock.hpp]


[heading Services]

This example demonstrates how to integrate custom functionality (in this case,
for logging) into asio's [link boost_asio.reference.io_context io_context], and
how to use a custom service with [link
boost_asio.reference.basic_stream_socket basic_stream_socket<>].

* [@boost_asio/example/cpp11/services/basic_logger.hpp]
* [@boost_asio/example/cpp11/services/daytime_client.cpp]
* [@boost_asio/example/cpp11/services/logger.hpp]
* [@boost_asio/example/cpp11/services/logger_service.cpp]
* [@boost_asio/example/cpp11/services/logger_service.hpp]
* [@boost_asio/example/cpp11/services/stream_socket_service.hpp]


[heading SOCKS 4]

Example client program implementing the SOCKS 4 protocol for communication via
a proxy.

* [@boost_asio/example/cpp11/socks4/sync_client.cpp]
* [@boost_asio/example/cpp11/socks4/socks4.hpp]


[heading Spawn]

Example of using the boost::asio::spawn() function, a wrapper around the
[@http://www.boost.org/doc/libs/release/libs/context/index.html Boost.Context]
library, to implement a chain of asynchronous operations using stackful
coroutines.

* [@boost_asio/example/cpp11/spawn/echo_server.cpp]


[heading SSL]

Example client and server programs showing the use of the [link
boost_asio.reference.ssl__stream ssl::stream<>] template with asynchronous operations.

* [@boost_asio/example/cpp11/ssl/client.cpp]
* [@boost_asio/example/cpp11/ssl/server.cpp]


[heading Timeouts]

A collection of examples showing how to cancel long running asynchronous
operations after a period of time.

* [@boost_asio/example/cpp11/timeouts/async_tcp_client.cpp]
* [@boost_asio/example/cpp11/timeouts/blocking_tcp_client.cpp]
* [@boost_asio/example/cpp11/timeouts/blocking_token_tcp_client.cpp]
* [@boost_asio/example/cpp11/timeouts/blocking_udp_client.cpp]
* [@boost_asio/example/cpp11/timeouts/server.cpp]


[heading Timers]

Example showing how to customise basic_waitable_timer using a different clock type.

* [@boost_asio/example/cpp11/timers/time_t_timer.cpp]


[heading Type Erasure]

Example showing how to use [link boost_asio.reference.any_completion_handler
`any_completion_handler`] to enable separate compilation of asynchronous
operations.

* [@boost_asio/example/cpp11/type_erasure/main.cpp]
* [@boost_asio/example/cpp11/type_erasure/line_reader.hpp]
* [@boost_asio/example/cpp11/type_erasure/stdin_line_reader.hpp]
* [@boost_asio/example/cpp11/type_erasure/stdin_line_reader.cpp]
* [@boost_asio/example/cpp11/type_erasure/sleep.hpp]
* [@boost_asio/example/cpp11/type_erasure/sleep.cpp]


[heading UNIX Domain Sockets]

Examples showing how to use UNIX domain (local) sockets.

* [@boost_asio/example/cpp11/local/connect_pair.cpp]
* [@boost_asio/example/cpp11/local/iostream_client.cpp]
* [@boost_asio/example/cpp11/local/stream_server.cpp]
* [@boost_asio/example/cpp11/local/stream_client.cpp]
* [@boost_asio/example/cpp11/local/fd_passing_stream_server.cpp]
* [@boost_asio/example/cpp11/local/fd_passing_stream_client.cpp]


[heading Windows]

An example showing how to use the Windows-specific function `TransmitFile`
with Boost.Asio.

* [@boost_asio/example/cpp11/windows/transmit_file.cpp]


[endsect]


[section:cpp14_examples C++14 Examples]


[heading Deferred]

Examples showing how to use the [link boost_asio.reference.deferred `deferred`]
completion token.

* [@boost_asio/example/cpp14/deferred/deferred_1.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_2.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_3.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_4.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_5.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_6.cpp]
* [@boost_asio/example/cpp14/deferred/deferred_7.cpp]


[heading Echo]

A collection of simple clients and servers, showing the use of both synchronous
and asynchronous operations.

* [@boost_asio/example/cpp14/echo/async_tcp_echo_server.cpp]
* [@boost_asio/example/cpp14/echo/async_udp_echo_server.cpp]
* [@boost_asio/example/cpp14/echo/blocking_tcp_echo_client.cpp]
* [@boost_asio/example/cpp14/echo/blocking_tcp_echo_server.cpp]
* [@boost_asio/example/cpp14/echo/blocking_udp_echo_client.cpp]
* [@boost_asio/example/cpp14/echo/blocking_udp_echo_server.cpp]


[heading Executors]

Examples showing how to use the executor-related facilities.

* [@boost_asio/example/cpp14/executors/actor.cpp]
* [@boost_asio/example/cpp14/executors/async_1.cpp]
* [@boost_asio/example/cpp14/executors/async_2.cpp]
* [@boost_asio/example/cpp14/executors/bank_account_1.cpp]
* [@boost_asio/example/cpp14/executors/bank_account_2.cpp]
* [@boost_asio/example/cpp14/executors/fork_join.cpp]
* [@boost_asio/example/cpp14/executors/pipeline.cpp]
* [@boost_asio/example/cpp14/executors/priority_scheduler.cpp]


[heading Iostreams]

Two examples showing how to use [link boost_asio.reference.ip__tcp.iostream
ip::tcp::iostream].

* [@boost_asio/example/cpp14/iostreams/http_client.cpp]


[heading Operations]

Examples showing how to implement composed asynchronous operations as reusable library functions.

* [@boost_asio/example/cpp14/operations/composed_1.cpp]
* [@boost_asio/example/cpp14/operations/composed_2.cpp]
* [@boost_asio/example/cpp14/operations/composed_3.cpp]
* [@boost_asio/example/cpp14/operations/composed_4.cpp]
* [@boost_asio/example/cpp14/operations/composed_5.cpp]
* [@boost_asio/example/cpp14/operations/composed_6.cpp]
* [@boost_asio/example/cpp14/operations/composed_7.cpp]
* [@boost_asio/example/cpp14/operations/composed_8.cpp]

Examples showing how to expose callback-based APIs as asynchronous operations.

* [@boost_asio/example/cpp14/operations/callback_wrapper.cpp]
* [@boost_asio/example/cpp14/operations/c_callback_wrapper.cpp]


[heading Parallel Groups]

Examples showing how to use the [link
boost_asio.reference.experimental__make_parallel_group
`experimental::make_parallel_group`] operation.

* [@boost_asio/example/cpp14/parallel_group/parallel_sort.cpp]
* [@boost_asio/example/cpp14/parallel_group/wait_for_all.cpp]
* [@boost_asio/example/cpp14/parallel_group/wait_for_one.cpp]
* [@boost_asio/example/cpp14/parallel_group/wait_for_one_error.cpp]
* [@boost_asio/example/cpp14/parallel_group/wait_for_one_success.cpp]
* [@boost_asio/example/cpp14/parallel_group/ranged_wait_for_all.cpp]


[endsect]


[section:cpp17_examples C++17 Examples]


[heading Coroutines TS Support]

Examples showing how to implement a chain of asynchronous operations using the
Coroutines TS.

* [@boost_asio/example/cpp17/coroutines_ts/echo_server.cpp]
* [@boost_asio/example/cpp17/coroutines_ts/refactored_echo_server.cpp]
* [@boost_asio/example/cpp17/coroutines_ts/chat_server.cpp]
* [@boost_asio/example/cpp17/coroutines_ts/range_based_for.cpp]


[endsect]


[section:cpp20_examples C++20 Examples]


[heading Channels]

Example showing how to use a channel in conjunction with C++20 coroutines.

* [@boost_asio/example/cpp20/channels/mutual_exclusion_1.cpp]
* [@boost_asio/example/cpp20/channels/mutual_exclusion_2.cpp]
* [@boost_asio/example/cpp20/channels/throttling_proxy.cpp]


[heading Coroutines]

Examples showing how to implement a chain of asynchronous operations using C++20
Coroutines.

* [@boost_asio/example/cpp20/coroutines/echo_server.cpp]
* [@boost_asio/example/cpp20/coroutines/echo_server_with_default.cpp]
* [@boost_asio/example/cpp20/coroutines/echo_server_with_as_tuple_default.cpp]
* [@boost_asio/example/cpp20/coroutines/echo_server_with_as_single_default.cpp]
* [@boost_asio/example/cpp20/coroutines/echo_server_with_deferred.cpp]
* [@boost_asio/example/cpp20/coroutines/echo_server_with_deferred_default.cpp]
* [@boost_asio/example/cpp20/coroutines/refactored_echo_server.cpp]
* [@boost_asio/example/cpp20/coroutines/chat_server.cpp]
* [@boost_asio/example/cpp20/coroutines/timeout.cpp]


[heading Invocation]

This example shows how to customise handler invocation using a user-defined
completion executor.

* [@boost_asio/example/cpp20/invocation/completion_executor.cpp]


[heading Operations]

Examples showing how to implement composed asynchronous operations as reusable library functions.

* [@boost_asio/example/cpp20/operations/composed_1.cpp]
* [@boost_asio/example/cpp20/operations/composed_2.cpp]
* [@boost_asio/example/cpp20/operations/composed_3.cpp]
* [@boost_asio/example/cpp20/operations/composed_4.cpp]
* [@boost_asio/example/cpp20/operations/composed_5.cpp]
* [@boost_asio/example/cpp20/operations/composed_6.cpp]
* [@boost_asio/example/cpp20/operations/composed_7.cpp]
* [@boost_asio/example/cpp20/operations/composed_8.cpp]

Examples showing how to expose callback-based APIs as asynchronous operations.

* [@boost_asio/example/cpp20/operations/callback_wrapper.cpp]
* [@boost_asio/example/cpp20/operations/c_callback_wrapper.cpp]


[heading Type Erasure]

Example showing how to use [link boost_asio.reference.any_completion_handler
`any_completion_handler`] to enable separate compilation of asynchronous
operations.

* [@boost_asio/example/cpp20/type_erasure/main.cpp]
* [@boost_asio/example/cpp20/type_erasure/line_reader.hpp]
* [@boost_asio/example/cpp20/type_erasure/stdin_line_reader.hpp]
* [@boost_asio/example/cpp20/type_erasure/stdin_line_reader.cpp]
* [@boost_asio/example/cpp20/type_erasure/sleep.hpp]
* [@boost_asio/example/cpp20/type_erasure/sleep.cpp]


[endsect]


[endsect]
