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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:47+00:00 2026-06-17T12:33:47+00:00

I am using boost::asio::ip::tcp::socket to send and receive data in a client/server application. I

  • 0

I am using boost::asio::ip::tcp::socketto send and receive data in a client/server application. I use simple selfmade data packets consisting of a header containing the size of the packet plus some flags and the “real” data.
I send my packets using boost::asio::write. In some cases I have a lot of packets to send to one client. Naive the fastest option would be to send them all at once. E.g.

 async_write(socket, buffer(p[0].str(),p[0].size()), &callback);
 async_write(socket, buffer(p[1].str(),p[1].size()), &callback);
 async_write(socket, buffer(p[2].str(),p[2].size()), &callback);

But if I do it like this, is there a guarantee that my packets arrive as a whole at the client? So in the example if the first 4 bytes of the packet represent the size of the remaining packet, can I call four times

uint32 size;
read(socket, buffer(&size,4));
char data[size];
read(socket, buffer(data,size));

and be sure that each data contains one packet (appart from the size uint32)? Or would it work if I send the next packet in the callback function?

If this infact works one other question is about the ordering. Can I be sure that the order, the packets arrive at the client, is the same as the one I send them from the server?

  • 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-17T12:33:48+00:00Added an answer on June 17, 2026 at 12:33 pm

    First and foremost, TCP sockets operate on streams of data, not packets. Secondly the async_write() documentation explicitly states a single outstanding operation per socket can be in-flight:

    This operation is implemented in terms of zero or more calls to the
    stream’s async_write_some function, and is known as a composed
    operation. The program must ensure that the stream performs no other
    write operations (such as async_write, the stream’s async_write_some
    function, or any other composed operations that perform writes) until
    this operation completes.

    You will need to chain your operations: invoke a second async_write() only after the completion handler for the first operation has been invoked.

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

Sidebar

Related Questions

When using a boost::asio::ip::tcp:socket there are many methods one can use to write/send data.
I working on a client/server application using boost asio, specifically boost::asio::ip::tcp::socket to connect and
I am trying to receive data from a server application using boost asio's async_read()
I'm writing a server application using boost::asio. I am reading known amount of data
I have a very simple server/client performance test using boost::asio on Windows and it
I have a socket server, written in C++ using boost::asio, and I'm sending data
I am trying to Create a simple Tcp Server in C++ using Boost ASio
I have a TCP server using boost asio. I have accepted a socket connection.
I have a TCP server using boost asio. I have accepted a socket connection.
I'm using the Boost::asio to implement a client/server applicaion. The client code below is

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.