Binary Data with boost::asio?

Started by
2 comments, last by wood_brian 12 years, 11 months ago
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?
Advertisement

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?

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. Here is some reading to get you started.

As frob says, it works fine with binary data but I would suggest looking at Google Protocol Buffers (http://code.google.com/apis/protocolbuffers/) 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.

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?



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
http://webEbenezer.net

This topic is closed to new replies.

Advertisement