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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:50:57+00:00 2026-06-11T18:50:57+00:00

Ive currently been messing around with boost trying it out. When i try to

  • 0

Ive currently been messing around with boost trying it out. When i try to make a simple multi threaded echo server it exits when receiving with error code 3. I have looked over the documentation many times and still no luck. I know it is probably something very simple i’m overlooking. I have decent experience with winsock but i would like to learn the boost library.

here is the code thats failing i took out the

typedef boost::shared_ptr<tcp::socket> socket_ptr;
boost::asio::io_service io;
boost::array<char, 512> buf;

void startserver ( std::string host, std::string port )
{
    tcp::acceptor a (io, tcp::endpoint(tcp::v4(), atoi(port.c_str())));
    for(;;)
    {
        socket_ptr sock (new tcp::socket(io));
        a.accept(*sock);
        std::cout << sock->remote_endpoint() << std::endl;
        boost::thread t (boost::bind(session, sock));
     }
}

void session ( socket_ptr sock ) 
{
    sock->send(boost::asio::buffer("welcome"),0,er);
    size_t len;
    for(;;)
    {
        len = sock->receive(boost::asio::buffer(buf));

        sock->send(boost::asio::buffer(buf,len),0,er);
    }

}

I can connect to it fine with netcat and it receives the welcome message but right when it goes to receive it crashs. Ive tried catching an error using boost::system::error_code on each one but nothing was returned

  • 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-11T18:50:58+00:00Added an answer on June 11, 2026 at 6:50 pm

    There are too many issues. Check asio documentation for correct examples. Some of issues:

    1. Creating boost::thread object t and then immediately exit scope. This deattaches thread and it not controllable now; or, as mentioned Joachim Pileborg it can terminate (im not very familiar with boost::threads, so correct me if i wrong).
    2. Right after this you starting new acceptor. You should hold only 1 acceptor per listening port.
    3. No point to create thread for this at all, it is ASIO, use async 😉
    4. receive does not wait data, it just fetch packet data ASIO already had (what is not true in this case)

    Check examples at boost site, i think your case is blocking tcp echo server

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

Sidebar

Related Questions

I've been messing around with something that should be simple. I've moved jobs and
I've been messing around for hours now trying to adjust the height of the
I've been trying to learn how to code in xslt and currently am stuck
I'm new to Google Apps and I've been messing around with the hello world
I've been messing around with CGI::application the past couple of days and decided to
I'm messing around with multidimensional arrays and pointers. I've been looking at a program
I've been messing around with a radiobox. I'm encountering an issue that varies depending
Okay so I've been messing around with Ruby quite a bit but am still
I've been messing around with this for a couple of months and I'm still
So I've been messing around with python's multiprocessing lib for the last few days

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.