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 an the documentation for an old version of boost. Click here for the latest Boost documentation.
basic_socket_streambuf::connect (3 of 3 overloads)

Inherited from basic_socket.

Connect the socket to the specified endpoint.

boost::system::error_code connect(
    const endpoint_type & peer_endpoint,
    boost::system::error_code & ec);

This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.

The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.



The remote endpoint to which the socket will be connected.


Set to indicate what error occurred, if any.

boost::asio::ip::tcp::socket socket(io_service);
boost::asio::ip::tcp::endpoint endpoint(
    boost::asio::ip::address::from_string(""), 12345);
boost::system::error_code ec;
socket.connect(endpoint, ec);
if (ec)
  // An error occurred.