| Home | Libraries | People | FAQ | More

##### basic_stream_socket::connect (1 of 2 overloads)

Inherited from basic_socket.

Connect the socket to the specified endpoint.

    void connect(
        const endpoint_type & peer_endpoint);

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.

###### Parameters

peer_endpoint

  The remote endpoint to which the socket will be connected.

###### Exceptions

boost::system::system_error

  Thrown on failure.

###### Example

    boost::asio::ip::tcp::socket socket(my_context);
    boost::asio::ip::tcp::endpoint endpoint(
        boost::asio::ip::address::from_string("1.2.3.4"), 12345);
    socket.connect(endpoint);