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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:32:54+00:00 2026-06-07T16:32:54+00:00

My Question is what is the best way to read off a boost tcp

  • 0

My Question is what is the best way to read off a boost tcp socket when you do not know the message size? this is a sample. I have simply put a size of 10.
code is in different headers but I did not feel the need to include it all

///////////// hpp

typedef boost::asio::ip::tcp::resolver TResolver;
typedef boost::asio::ip::tcp::resolver::query TResolverQuery;
typedef boost::asio::ip::tcp::endpoint Tendpoint;
typedef boost::asio::ip::tcp::socket Tsocket;
typedef boost::asio::ip::tcp::acceptor Tacceptor;
#define Tsize 10

//////////// cpp

while(true)
{
    cout<<"recieve"<<endl;
    boost::shared_ptr< Tacceptor > acceptor(new boost::asio::ip::tcp::acceptor(*m_io_service));
    boost::system::error_code ec;
    TResolverQuery query(this->getHost(), boost::lexical_cast< std::string >( this->getPort() ));
    TResolver resolver( *m_io_service );
    Tendpoint endpoint = *resolver.resolve( query );
    acceptor->open( endpoint.protocol() );
    acceptor->set_option( boost::asio::ip::tcp::acceptor::reuse_address( true ) );
    acceptor->bind( endpoint );
    acceptor->listen();
    boost::shared_ptr< Tsocket > socknew(new Tsocket( *m_io_service ));
    acceptor->accept( *socknew,endpoint);
    boost::array<char, Tsize> buf;
    boost::asio::read(*socknew,boost::asio::buffer(buf), ec);
    cout.write(buf.data(),Tsize);cout << std::endl;
    socknew->shutdown( boost::asio::ip::tcp::socket::shutdown_both, ec );
    cout<<"threadId "<< boost::this_thread::get_id()<<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-07T16:32:57+00:00Added an answer on June 7, 2026 at 4:32 pm

    The two most common methods is to use a protocol that either contains the length of the message, or has a end-of-message marker.

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

Sidebar

Related Questions

I recently read the the following SO question. What's the best way to store
This question ( Best way to strip punctuation from a string in Python )
This question is related to this one: Best way to store product colors in
This is the best way I can think of phrasing this question, given this
This question is somewhat similar to this one Best way to deploy large *.war
I'm not sure if decorators are the best way to do this, but I've
I found another similar question: Best way to download images from XML content in
Question: What is the best way to set focus to a web control in
My question is: What is the best way to port the data back and
General question about java servlets and the best way to handle requests. If I

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.