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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
basic_datagram_socket::bind (2 of 2 overloads)

Inherited from basic_socket.

Bind the socket to the given local endpoint.

void bind(
    const endpoint_type & endpoint,
    boost::system::error_code & ec);

This function binds the socket to the specified endpoint on the local machine.

Parameters

endpoint

An endpoint on the local machine to which the socket will be bound.

ec

Set to indicate what error occurred, if any.

Example
boost::asio::ip::tcp::socket socket(my_context);
socket.open(boost::asio::ip::tcp::v4());
boost::system::error_code ec;
socket.bind(boost::asio::ip::tcp::endpoint(
      boost::asio::ip::tcp::v4(), 12345), ec);
if (ec)
{
  // An error occurred.
}

PrevUpHomeNext