| Home | Libraries | People | FAQ | More

###### basic_stream::connect (6 of 10 overloads)

Establishes a connection by trying each endpoint in a sequence.

<h7> Synopsis </h7>

    template<
        class Iterator>
    Iterator
    connect(
        Iterator begin,
        Iterator end,
        error_code& ec);

<h7> Description </h7>

This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. The underlying socket is automatically opened if needed. An automatically opened socket is not returned to the closed state upon failure. The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function.

<h7> Parameters </h7>

Name | Description
--- | ---
`begin` | An iterator pointing to the start of a sequence of endpoints.
`end` | An iterator pointing to the end of a sequence of endpoints.
`ec` | Set to indicate what error occurred, if any. If the sequence is empty, set to boost::asio::error::not_found. Otherwise, contains the error from the last connection attempt.

<h7> Return Value </h7>

On success, an iterator denoting the successfully connected endpoint. Otherwise, the end iterator.