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

  • Home
  • SEARCH
  • 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 the latest version of protobuf-net with VS2008 integration. I have created
I am using the latest version of Twitter Bootstrap on a project. I have
Im using latest TCPDF version(5.9). But have some strange problems with encoding. I need
I am using the latest version 3.4.b3. I have it in a dialog and
I am using the latest version of DevExpress XtratreeList and have a requirement of
I am using latest version of jQuery Autocompletion plugin and have populated an array
Using the latest version of EasyMock, I have a method that I need to
I am using the latest version of MySQL 5.5. I have a fulltext index
Using the latest version of Resharper (4.5.x) with VS2008. Every now and then (pretty
I'm using the latest version of the jquery plugin DataTables and I tried to

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.