Asynchronous reading is a flexible and efficient way to receive data from a remote application. In this recipe, we will see how to read data from a TCP socket asynchronously.
The most basic tool used to asynchronously read data from a TCP socket provided by the Boost.Asio library is the
async_read_some() method of the
asio::ip::tcp::socket class. Here is one of the method's overloads:
template< typename MutableBufferSequence, typename ReadHandler> void async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
This method initiates an asynchronous read operation and returns immediately. It accepts an object that represents a mutable buffer as its first argument to which the ...