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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:43:21+00:00 2026-05-23T08:43:21+00:00

I am using the C++ boost asio library, where I listen to new connections

  • 0

I am using the C++ boost asio library, where I listen to new connections on the socket. On getting a connection I process the request and then listen for a new connection on another socket in a loop.

while (true)
{
    tcp::socket soc(this->blitzIOService);
    this->blitzAcceptor.listen();
    boost::system::error_code ec;
    this->blitzAcceptor.accept(soc,ec);
    if (ec)
    {
        // Some error occured
        cerr << "Error Value: " << ec.value() << endl;
        cerr << "Error Message: " << ec.message() << endl;
        soc.close();
        break;
    }
    else
    {
        this->HandleRequest(soc);
        soc.shutdown(tcp::socket::shutdown_both);
        soc.close();
    }
}

According to my understanding it should always block at this->blitzAcceptor.accept(soc,ec); and everytime a new connection is made it should handle it in this->HandleRequest(soc); and again block at this->blitzAcceptor.accept(soc,ec);

But what I see is this that for the first time it will block at this->blitzAcceptor.accept(soc,ec) and when a new connection is made it will handle the request, but instead of blocking again at this->blitzAcceptor.accept(soc,ec) it will go ahead into this->HandleRequest(soc); and block at soc.receive(); inside.

This doesn’t happen always, but happens most of the time. What could be the reason to this behavior, and how can I ensure that it always block at this->blitzAcceptor.accept(soc,ec) until a new request is made?

  • 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-23T08:43:22+00:00Added an answer on May 23, 2026 at 8:43 am

    What could be the reason to this
    behavior?

    This behavior is entirely dependent on the client code. If it connects, but does not send a request, the server with block when receiving data.

    how can I ensure that it always block
    at this->blitzAcceptor.accept(soc,ec)
    until a new request is made?

    You can’t. But your server can initiate a timeout that starts immediately after accepting the connection. If the client does not send a request within that duration, close the socket. To do that, you should switch to using asynchronous methods rather than synchronous methods.

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

Sidebar

Related Questions

I'm in the process of converting my non secure socket to ssl, using boost::asio::ssl
I am using boost::asio to make a socket network. The library has a number
I have a TCP server using boost asio. I have accepted a socket connection.
I am using Boost Asio to set up a socket connection. I would like
How can I listen to two socket simultaneously using boost::asio? I think there shouldn't
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
Greetings. I'm just getting started with the boost::asio library and have run into some
The following code using boost::asio will not compile: #ifndef _SERVER_H_ #define _SERVER_H_ #include Connection.h
I am using boost::asio::ip::udp::socket to communicate. I use socket.receive_from(...) to receive messages from clients.

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.