### C++11 Examples

##### Allocation

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

- examples/cpp11/allocation/server.cpp

##### Buffers

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

- examples/cpp11/buffers/reference_counted.cpp

##### 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.

- examples/cpp11/chat/chat_message.hpp
- examples/cpp11/chat/chat_client.cpp
- examples/cpp11/chat/chat_server.cpp

The following POSIX-specific chat client demonstrates how to use the posix::stream_descriptor class to perform console input and output.

- examples/cpp11/chat/posix_chat_client.cpp

##### Deferred

Examples showing how to use the `deferred` completion token.

- examples/cpp11/deferred/deferred_1.cpp
- examples/cpp11/deferred/deferred_2.cpp

##### Echo

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

- examples/cpp11/echo/async_tcp_echo_server.cpp
- examples/cpp11/echo/async_udp_echo_server.cpp
- examples/cpp11/echo/blocking_tcp_echo_client.cpp
- examples/cpp11/echo/blocking_tcp_echo_server.cpp
- examples/cpp11/echo/blocking_udp_echo_client.cpp
- examples/cpp11/echo/blocking_udp_echo_server.cpp

##### Fork

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

- examples/cpp11/fork/daemon.cpp

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

- examples/cpp11/fork/process_per_connection.cpp

##### Futures

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

- examples/cpp11/futures/daytime_client.cpp

##### Handler Tracking

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

- examples/cpp11/handler_tracking/custom_tracking.hpp

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

- examples/cpp11/handler_tracking/async_tcp_echo_server.cpp

##### HTTP Client

Example programs implementing simple HTTP 1.0 clients. These examples show how to use the read_until and async_read_until functions.

- examples/cpp11/http/client/sync_client.cpp
- examples/cpp11/http/client/async_client.cpp

##### 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.

- examples/cpp11/http/server/connection.cpp
- examples/cpp11/http/server/connection.hpp
- examples/cpp11/http/server/connection_manager.cpp
- examples/cpp11/http/server/connection_manager.hpp
- examples/cpp11/http/server/header.hpp
- examples/cpp11/http/server/main.cpp
- examples/cpp11/http/server/mime_types.cpp
- examples/cpp11/http/server/mime_types.hpp
- examples/cpp11/http/server/reply.cpp
- examples/cpp11/http/server/reply.hpp
- examples/cpp11/http/server/request.hpp
- examples/cpp11/http/server/request_handler.cpp
- examples/cpp11/http/server/request_handler.hpp
- examples/cpp11/http/server/request_parser.cpp
- examples/cpp11/http/server/request_parser.hpp
- examples/cpp11/http/server/server.cpp
- examples/cpp11/http/server/server.hpp

##### HTTP Server 2

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

- examples/cpp11/http/server2/connection.cpp
- examples/cpp11/http/server2/connection.hpp
- examples/cpp11/http/server2/header.hpp
- examples/cpp11/http/server2/io_context_pool.cpp
- examples/cpp11/http/server2/io_context_pool.hpp
- examples/cpp11/http/server2/main.cpp
- examples/cpp11/http/server2/mime_types.cpp
- examples/cpp11/http/server2/mime_types.hpp
- examples/cpp11/http/server2/reply.cpp
- examples/cpp11/http/server2/reply.hpp
- examples/cpp11/http/server2/request.hpp
- examples/cpp11/http/server2/request_handler.cpp
- examples/cpp11/http/server2/request_handler.hpp
- examples/cpp11/http/server2/request_parser.cpp
- examples/cpp11/http/server2/request_parser.hpp
- examples/cpp11/http/server2/server.cpp
- examples/cpp11/http/server2/server.hpp

##### HTTP Server 3

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

- examples/cpp11/http/server3/connection.cpp
- examples/cpp11/http/server3/connection.hpp
- examples/cpp11/http/server3/header.hpp
- examples/cpp11/http/server3/main.cpp
- examples/cpp11/http/server3/mime_types.cpp
- examples/cpp11/http/server3/mime_types.hpp
- examples/cpp11/http/server3/reply.cpp
- examples/cpp11/http/server3/reply.hpp
- examples/cpp11/http/server3/request.hpp
- examples/cpp11/http/server3/request_handler.cpp
- examples/cpp11/http/server3/request_handler.hpp
- examples/cpp11/http/server3/request_parser.cpp
- examples/cpp11/http/server3/request_parser.hpp
- examples/cpp11/http/server3/server.cpp
- examples/cpp11/http/server3/server.hpp

##### HTTP Server 4

A single-threaded HTTP server implemented using stackless coroutines.

- examples/cpp11/http/server4/file_handler.cpp
- examples/cpp11/http/server4/file_handler.hpp
- examples/cpp11/http/server4/header.hpp
- examples/cpp11/http/server4/main.cpp
- examples/cpp11/http/server4/mime_types.cpp
- examples/cpp11/http/server4/mime_types.hpp
- examples/cpp11/http/server4/reply.cpp
- examples/cpp11/http/server4/reply.hpp
- examples/cpp11/http/server4/request.hpp
- examples/cpp11/http/server4/request_parser.cpp
- examples/cpp11/http/server4/request_parser.hpp
- examples/cpp11/http/server4/server.cpp
- examples/cpp11/http/server4/server.hpp

##### ICMP

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

- examples/cpp11/icmp/ping.cpp
- examples/cpp11/icmp/ipv4_header.hpp
- examples/cpp11/icmp/icmp_header.hpp

##### Invocation

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

- examples/cpp11/invocation/prioritised_handlers.cpp

##### Iostreams

Two examples showing how to use ip::tcp::iostream.

- examples/cpp11/iostreams/daytime_client.cpp
- examples/cpp11/iostreams/daytime_server.cpp
- examples/cpp11/iostreams/http_client.cpp

##### Multicast

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

- examples/cpp11/multicast/receiver.cpp
- examples/cpp11/multicast/sender.cpp

##### Nonblocking

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

- examples/cpp11/nonblocking/third_party_lib.cpp

##### Operations

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

- examples/cpp11/operations/composed_1.cpp
- examples/cpp11/operations/composed_2.cpp
- examples/cpp11/operations/composed_3.cpp
- examples/cpp11/operations/composed_4.cpp
- examples/cpp11/operations/composed_5.cpp
- examples/cpp11/operations/composed_6.cpp
- examples/cpp11/operations/composed_7.cpp
- examples/cpp11/operations/composed_8.cpp

##### Parallel Groups

Examples showing how to use the `experimental::make_parallel_group` operation.

- examples/cpp11/parallel_group/wait_for_all.cpp
- examples/cpp11/parallel_group/wait_for_one.cpp
- examples/cpp11/parallel_group/wait_for_one_error.cpp
- examples/cpp11/parallel_group/wait_for_one_success.cpp
- examples/cpp11/parallel_group/ranged_wait_for_all.cpp

##### Porthopper

Example illustrating mixed synchronous and asynchronous operations.

- examples/cpp11/porthopper/protocol.hpp
- examples/cpp11/porthopper/client.cpp
- examples/cpp11/porthopper/server.cpp

##### Serialization

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

- examples/cpp11/serialization/client.cpp
- examples/cpp11/serialization/connection.hpp
- examples/cpp11/serialization/server.cpp
- examples/cpp11/serialization/stock.hpp

##### Services

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

- examples/cpp11/services/basic_logger.hpp
- examples/cpp11/services/daytime_client.cpp
- examples/cpp11/services/logger.hpp
- examples/cpp11/services/logger_service.cpp
- examples/cpp11/services/logger_service.hpp
- examples/cpp11/services/stream_socket_service.hpp

##### SOCKS 4

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

- examples/cpp11/socks4/sync_client.cpp
- examples/cpp11/socks4/socks4.hpp

##### Spawn

Example of using the asio::spawn() function, a wrapper around the Boost.Context library, to implement a chain of asynchronous operations using stackful coroutines.

- examples/cpp11/spawn/echo_server.cpp

##### SSL

Example client and server programs showing the use of the ssl::stream<> template with asynchronous operations.

- examples/cpp11/ssl/client.cpp
- examples/cpp11/ssl/server.cpp

##### Timeouts

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

- examples/cpp11/timeouts/async_tcp_client.cpp
- examples/cpp11/timeouts/blocking_tcp_client.cpp
- examples/cpp11/timeouts/blocking_token_tcp_client.cpp
- examples/cpp11/timeouts/blocking_udp_client.cpp
- examples/cpp11/timeouts/server.cpp

##### Timers

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

- examples/cpp11/timers/time_t_timer.cpp

##### Type Erasure

Example showing how to use `any_completion_handler` to enable separate compilation of asynchronous operations.

- examples/cpp11/type_erasure/main.cpp
- examples/cpp11/type_erasure/line_reader.hpp
- examples/cpp11/type_erasure/stdin_line_reader.hpp
- examples/cpp11/type_erasure/stdin_line_reader.cpp
- examples/cpp11/type_erasure/sleep.hpp
- examples/cpp11/type_erasure/sleep.cpp

##### UNIX Domain Sockets

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

- examples/cpp11/local/connect_pair.cpp
- examples/cpp11/local/iostream_client.cpp
- examples/cpp11/local/stream_server.cpp
- examples/cpp11/local/stream_client.cpp
- examples/cpp11/local/fd_passing_stream_server.cpp
- examples/cpp11/local/fd_passing_stream_client.cpp

##### Windows

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

- examples/cpp11/windows/transmit_file.cpp