Boost C++ Libraries

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

Click here to view the latest version of this page.
PrevUpHomeNext
basic_datagram_socket::send_to (1 of 3 overloads)

Send a datagram to the specified endpoint.

template<
    typename ConstBufferSequence>
std::size_t send_to(
    const ConstBufferSequence & buffers,
    const endpoint_type & destination);

This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.

Parameters

buffers

One or more data buffers to be sent to the remote endpoint.

destination

The remote endpoint to which the data will be sent.

Return Value

The number of bytes sent.

Exceptions

boost::system::system_error

Thrown on failure.

Example

To send a single data buffer use the buffer function as follows:

boost::asio::ip::udp::endpoint destination(
    boost::asio::ip::address::from_string("1.2.3.4"), 12345);
socket.send_to(boost::asio::buffer(data, size), destination);

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


PrevUpHomeNext