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 9282489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:23:21+00:00 2026-06-18T18:23:21+00:00

I have an Server, using asio with the following code, 100% copied from the

  • 0

I have an Server, using asio with the following code, 100% copied from the examples. The code behaves well when there are no connections. however, as soon as the first client connects, handle accept starts to output vast amounts of system:9 errors and I am unable to connect any other clients. The single client that is connected can perform async read/writes just fine. I’m at a loss at what I’m doing incorrectly. I’ve tried the code with and without io_service in a thread pool with the same results.

Server::Server(io_service& io_service,
      const std::string address,
      const std::string port)
    : io_service_(io_service),
    //zmq_strand_(io_service),
      acceptor_(io_service) {

    ip::tcp::resolver resolver(io_service_);
    ip::tcp::resolver::query query(address, port);
    ip::tcp::endpoint endpoint = *resolver.resolve(query);
    acceptor_.open(endpoint.protocol());
    acceptor_.set_option(ip::tcp::acceptor::reuse_address(true));
    acceptor_.bind(endpoint);
    acceptor_.listen(); 
    start_accept();
  }

void Server::start_accept() {
    auto session = std::shared_ptr<Session>(new Session(io_service_,session_manager_));

    acceptor_.async_accept(session->socket()
        ,std::bind(&Server::handle_accept,this,session,std::placeholders::_1));
}

void Server::handle_accept(std::shared_ptr<Session> session, const system::error_code& error) {
  if (!error) {
    std::cout << "handle_accept" << std::endl;
    session->start();
  } else {
      std::cout << error << std::endl;
  }
  start_accept();
}

small update:
Instead of using the http3 example I used the example Denis proposed. It’s less convoluted and made the server behave correctly. I haven’t found a rational explanation to why the previous piece of code doesn’t work. This does:

Server::Server(
      io_service &service,
      const uint8_t num_threads,
      const std::string address,
      const uint16_t port)
    : 
      num_threads_(num_threads),
    //zmq_strand_(io_service),
      acceptor_(service,ip::tcp::endpoint(ip::tcp::v4(),port)) {

    //io_service::work work(io_service_);
    start_accept();
  }


void Server::start_accept() {
    auto session = std::shared_ptr<Session>(new Session(acceptor_.get_io_service(),session_manager_));

    acceptor_.async_accept(session->socket()
        ,std::bind(&Server::handle_accept,this,session,std::placeholders::_1));
}

void Server::handle_accept(std::shared_ptr<Session> session, const system::error_code& error) {
  if (!error) {
    std::cout << "handle_accept" << std::endl;
    session->start();
  }
  start_accept();
}

void Server::start() {
    std::set<std::unique_ptr<std::thread>> threads;

    for( unsigned int i = 0; i < num_threads_; ++i ) {
        threads.insert(std::unique_ptr<std::thread>(new std::thread( [&]() {
            acceptor_.get_io_service().run();
            }) 
        ));
    }
    std::cout << threads.size() << " threads started" << std::endl;
    for(auto &t:threads) {
        t->join();
    }
    std::cout << threads.size() << " threads joined" << std::endl;
}
  • 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-06-18T18:23:22+00:00Added an answer on June 18, 2026 at 6:23 pm

    Look precisely at this tutorial and compare your code with tutorial: Boost TCP async server example

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

Sidebar

Related Questions

I'm trying to write a SSL-based async server using Boost ASIO example code from
i have a c++ server which is using boost::asio to do read/write operations -
I have developed a Java server using Eclipse that accepts TCP socket connection from
I have a server-side code using .NET Remoting to establish the connection with client.
I have a program that gets a JSON from the server using getJSON and
I'm writing server using boost.asio. I have read and write buffer for each connection
I have a socket server, written in C++ using boost::asio, and I'm sending data
I have a very simple server/client performance test using boost::asio on Windows and it
I have a server implemented using Apache HTTPCore which can accept posts from an
I'm writing a cross-platform server program in C++ using Boost.Asio. Following the HTTP Server

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.