• Advertisement
Sign in to follow this  

Binary Data with boost::asio?

This topic is 2414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,



I just read some of the tutorials of boost::asio and also had a short look into the reference.

In the tutorials only chars are sent.

I am wondering about how it works with binary data. Ofcourse you can convert an 4-byte int into 4 chars, but then you will have problems with endianess.

Is there a good way to send and receive binary data with boost::asio which works platform independently?

Do I maybe need to write my own conversions functions which handle endianess?

Share this post


Link to post
Share on other sites
Advertisement
[quote name='P@u1' timestamp='1307893142' post='4822413']
Hi everyone,



I just read some of the tutorials of boost::asio and also had a short look into the reference.

In the tutorials only chars are sent.

I am wondering about how it works with binary data. Ofcourse you can convert an 4-byte int into 4 chars, but then you will have problems with endianess.

Is there a good way to send and receive binary data with boost::asio which works platform independently?

Do I maybe need to write my own conversions functions which handle endianess?
[/quote]
It sends binary data, but treats it as char blocks.

You need to serialize your data into something that you can send, and then deserialize it on the other end. [url="http://www.google.com/search?q=c%2B%2B+serialization"]Here is some reading[/url] to get you started.

Share this post


Link to post
Share on other sites
As frob says, it works fine with binary data but I would suggest looking at Google Protocol Buffers ([url="http://code.google.com/apis/protocolbuffers/"]http://code.google.com/apis/protocolbuffers/[/url]) as a very good starting point. Boost serialization is acceptable of course but the protocol buffers are designed specifically for the job and are faster than the Boost serialization system. Admittedly it takes a bit more to integrate into the build pipeline but it is worth the effort.

Share this post


Link to post
Share on other sites
[quote name='P@u1' timestamp='1307893142' post='4822413']
Hi everyone,



I just read some of the tutorials of boost::asio and also had a short look into the reference.

In the tutorials only chars are sent.

I am wondering about how it works with binary data. Ofcourse you can convert an 4-byte int into 4 chars, but then you will have problems with endianess.

Is there a good way to send and receive binary data with boost::asio which works platform independently?

Do I maybe need to write my own conversions functions which handle endianess?
[/quote]


I'm working on an on line approach to marshalling C++ objects called the C++ Middleware Writer.
I'm looking for people interested in using the C++ Middleware Writer and am willing to donate 18 hours/week for six months to a project that uses the C++ Middleware Writer. In addition, I'm offering a referral bonus of $175/month for four months if you refer someone to me who I end up working with.


Brian Wood
Ebenezer Enterprises
[url="http://webEbenezer.net"]http://webEbenezer.net[/url]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement