The function handle_accept() is called when the asynchronous accept
operation initiated by start_accept() finishes. It services the client request,
and then calls start_accept() to initiate the next accept operation.

In the function start(),
we call asio::async_write() to serve the data to the client. Note that we
are using asio::async_write(), rather than ip::tcp::socket::async_write_some(),
to ensure that the entire block of data is sent.

voidstart(){

The data to be sent is stored in the class member message_
as we need to keep the data valid until the asynchronous operation is complete.

message_=make_daytime_string();

When initiating the asynchronous operation, and if using boost::bind
, you must specify only the arguments that match the handler's parameter
list. In this program, both of the argument placeholders (asio::placeholders::error
and asio::placeholders::bytes_transferred) could potentially have been removed,
since they are not being used in handle_write().

You may have noticed that the error,
and bytes_transferred parameters
are not used in the body of the handle_write() function. If parameters are not needed,
it is possible to remove them from the function so that it looks like:

voidhandle_write(){}

The asio::async_write() call used to initiate the call can then be changed
to just: