Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally, once you've made a call to <code>io_service::run</code>, there's often few reasons to call <code>io_service::stop</code> or <code>io_service::reset</code>. </p> <p>In your code above, the <code>connect</code> method is <em>not</em> going to actively establish a connection - <code>tcp::resolver::resolve</code> merely turns a query (such as a hostname, or an IP address, etc.) into a TCP endpoint which can be used to connect a socket. You typically need to dereference an iterator returned by <code>resolver::resolve</code> and pass it to a <code>boost::asio::ip::tcp::socket</code> object's <code>connect</code> method (or one of the asynchronous varieties) to connect an endpoint.</p> <p>The Asio tutorials have a good example of this. See the first synchronous TCP daytime server example here: <a href="http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime1.html" rel="nofollow noreferrer">http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime1.html</a>. Note that the code first runs:</p> <pre><code>tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); </code></pre> <p>to turn a query object into a TCP endpoint, and then:</p> <pre><code>socket.connect(*endpoint_iterator++, error); </code></pre> <p>to connect a socket object on that endpoint.</p> <p>As for what should go in your <code>disconnect</code> method, that's entirely dependent on the application. But usually you'll need to keep track of an active connection by encapsulating a <code>socket</code> object, which you can close as necessary when you call <code>disconnect</code>. For an example of this, have a look at the tutorial titled "Daytime 3 - An Asynchronous TCP daytime server" here: <a href="http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime3.html" rel="nofollow noreferrer">http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime3.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload