• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>connect (5 of 12 overloads)</title>
5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../boost_asio.html" title="Boost.Asio">
8<link rel="up" href="../connect.html" title="connect">
9<link rel="prev" href="overload4.html" title="connect (4 of 12 overloads)">
10<link rel="next" href="overload6.html" title="connect (6 of 12 overloads)">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="overload4.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../connect.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload6.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="boost_asio.reference.connect.overload5"></a><a class="link" href="overload5.html" title="connect (5 of 12 overloads)">connect (5
28        of 12 overloads)</a>
29</h4></div></div></div>
30<p>
31          Establishes a socket connection by trying each endpoint in a sequence.
32        </p>
33<pre class="programlisting">template&lt;
34    typename <a class="link" href="../Protocol.html" title="Protocol requirements">Protocol</a>,
35    typename <a class="link" href="../Executor1.html" title="Executor requirements">Executor</a>,
36    typename Iterator&gt;
37Iterator connect(
38    basic_socket&lt; Protocol, Executor &gt; &amp; s,
39    Iterator begin,
40    Iterator end);
41</pre>
42<p>
43          This function attempts to connect a socket to one of a sequence of endpoints.
44          It does this by repeated calls to the socket's <code class="computeroutput">connect</code> member
45          function, once for each endpoint in the sequence, until a connection is
46          successfully established.
47        </p>
48<h6>
49<a name="boost_asio.reference.connect.overload5.h0"></a>
50          <span class="phrase"><a name="boost_asio.reference.connect.overload5.parameters"></a></span><a class="link" href="overload5.html#boost_asio.reference.connect.overload5.parameters">Parameters</a>
51        </h6>
52<div class="variablelist">
53<p class="title"><b></b></p>
54<dl class="variablelist">
55<dt><span class="term">s</span></dt>
56<dd><p>
57                The socket to be connected. If the socket is already open, it will
58                be closed.
59              </p></dd>
60<dt><span class="term">begin</span></dt>
61<dd><p>
62                An iterator pointing to the start of a sequence of endpoints.
63              </p></dd>
64<dt><span class="term">end</span></dt>
65<dd><p>
66                An iterator pointing to the end of a sequence of endpoints.
67              </p></dd>
68</dl>
69</div>
70<h6>
71<a name="boost_asio.reference.connect.overload5.h1"></a>
72          <span class="phrase"><a name="boost_asio.reference.connect.overload5.return_value"></a></span><a class="link" href="overload5.html#boost_asio.reference.connect.overload5.return_value">Return Value</a>
73        </h6>
74<p>
75          An iterator denoting the successfully connected endpoint.
76        </p>
77<h6>
78<a name="boost_asio.reference.connect.overload5.h2"></a>
79          <span class="phrase"><a name="boost_asio.reference.connect.overload5.exceptions"></a></span><a class="link" href="overload5.html#boost_asio.reference.connect.overload5.exceptions">Exceptions</a>
80        </h6>
81<div class="variablelist">
82<p class="title"><b></b></p>
83<dl class="variablelist">
84<dt><span class="term">boost::system::system_error</span></dt>
85<dd><p>
86                Thrown on failure. If the sequence is empty, the associated <code class="computeroutput">error_code</code>
87                is <code class="computeroutput">boost::asio::error::not_found</code>. Otherwise, contains
88                the error from the last connection attempt.
89              </p></dd>
90</dl>
91</div>
92<h6>
93<a name="boost_asio.reference.connect.overload5.h3"></a>
94          <span class="phrase"><a name="boost_asio.reference.connect.overload5.example"></a></span><a class="link" href="overload5.html#boost_asio.reference.connect.overload5.example">Example</a>
95        </h6>
96<pre class="programlisting">tcp::resolver r(my_context);
97tcp::resolver::query q("host", "service");
98tcp::resolver::results_type e = r.resolve(q);
99tcp::socket s(my_context);
100boost::asio::connect(s, e.begin(), e.end());
101</pre>
102</div>
103<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
104<td align="left"></td>
105<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
106      Kohlhoff<p>
107        Distributed under the Boost Software License, Version 1.0. (See accompanying
108        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
109      </p>
110</div></td>
111</tr></table>
112<hr>
113<div class="spirit-nav">
114<a accesskey="p" href="overload4.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../connect.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload6.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
115</div>
116</body>
117</html>
118