Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
basic_stream_socket::receive (1 of 3 overloads)

Receive some data on the socket.

    typename MutableBufferSequence>
std::size_t receive(
    const MutableBufferSequence & buffers);

This function is used to receive data on the stream socket. The function call will block until one or more bytes of data has been received successfully, or until an error occurs.



One or more buffers into which the data will be received.

Return Value

The number of bytes received.



Thrown on failure. An error code of boost::asio::error::eof indicates that the connection was closed by the peer.


The receive operation may not receive all of the requested number of bytes. Consider using the read function if you need to ensure that the requested amount of data is read before the blocking operation completes.


To receive into a single data buffer use the buffer function as follows:

socket.receive(boost::asio::buffer(data, size));

See the buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.