Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 791899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:54:35+00:00 2026-05-14T21:54:35+00:00

I am using the latest version of boost and boost.asio. I have this class:

  • 0

I am using the latest version of boost and boost.asio.
I have this class:

enum IPVersion
{
    IPv4,
    IPv6
};

template <IPVersion version = IPv4>
class Connection
{
private:
    boost::asio::io_service io_service;
    boost::asio::ip::tcp::resolver resolver;
    boost::asio::ip::tcp::resolver::query query;
    boost::asio::ip::tcp::resolver::iterator iterator;
public:
    Connection(std::string host, std::string port);

    virtual void connect() { iterator = resolver.resolve(query); } // Is this the moment where the client actually connects?
    virtual void disconnect() { /* what goes in here? */ }
};

Should I call io_service::stop() and then on my Connection::connect() call io_service::reset() first before I resolve the query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:54:36+00:00Added an answer on May 14, 2026 at 9:54 pm

    Generally, once you’ve made a call to io_service::run, there’s often few reasons to call io_service::stop or io_service::reset.

    In your code above, the connect method is not going to actively establish a connection – tcp::resolver::resolve 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 resolver::resolve and pass it to a boost::asio::ip::tcp::socket object’s connect method (or one of the asynchronous varieties) to connect an endpoint.

    The Asio tutorials have a good example of this. See the first synchronous TCP daytime server example here: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime1.html. Note that the code first runs:

    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    

    to turn a query object into a TCP endpoint, and then:

    socket.connect(*endpoint_iterator++, error);
    

    to connect a socket object on that endpoint.

    As for what should go in your disconnect method, that’s entirely dependent on the application. But usually you’ll need to keep track of an active connection by encapsulating a socket object, which you can close as necessary when you call disconnect. For an example of this, have a look at the tutorial titled “Daytime 3 – An Asynchronous TCP daytime server” here: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime3.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using latest version of jQuery Autocompletion plugin and have populated an array
I have a user who is using the latest version of OSX and Safari.
I am currently building an Excel 2007 Add-in using VSTO (latest version + sp1)
Using online interfaces to a version control system is a nice way to have
I downloaded the latest version of Boost and I'm trying to get the Boost.python
My configure.in file has LT_VERSION=1.1 . I am using the latest version of autoconf
I just started to dig into Boost::Spirit, latest version by now -- V2.4. The
I have ubuntu 10.04 and want to install the latest boost library 1.44_0 I
I am using the latest version of the official Amazon S3 SDK (1.0.14.1) to
I'm using the latest version of jFeed with the latest jQuery. I know jFeed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.