Boost logo

Boost Users :

From: Christian Henning (chhenning_at_[hidden])
Date: 2007-01-08 15:02:34


Hi Gerd, I'm sure you know that already. But, have you taken a look at
boost::asio? There is even an example for using the serialization lib
when sending objects over a socket.

Here a link:
http://asio.sourceforge.net/boost_asio_0_3_7/libs/asio/doc/examples/index.html

Just scroll down a bit to the Serialization section.

Christian

On 1/8/07, Gerd Ritter <gerd.ritter_at_[hidden]> wrote:
>
> Hi,
>
> I have a more fundamental question/inquiry about the serialization library.
>
> What I want to do is to use the serialization library to send classes over a
> socket. Even though archives are not supposed to be used at streams I
> figured that it should be possible to create a oarchive on the sender side,
> create a iarchive on the receiver side, and use these for multiple,
> successive write / read operations in block mode.
> In order to test that assumption I created a test program to see if it would
> be possible. Here the pseudo code:
>
>
> void sync_streams(stringstream &os, stringstream& os)
> {
> // write data from one sting stream to the other
> // this emulates sending the data on a socket
>
>
> int rd_avail = os.tellp() - os.tellg();
> os.read(buffer, rd_avail);
> is.write(buffer, rd_avail);
> }
>
> stringstream os, is;
>
> boost::archive::text_oarchive oa(os);
> sync_streams(os, is); // sync preamble
> boost::archive::text_iarchive ia(is);
>
>
> oa << object1;
> sync_streams(os, is); // sync object block
> ia >> rdObject1;
>
>
> oa << object2;
> sync_streams(os, is); // sync object block
> ia >> rdObject2;
>
>
> While I made this work, I wonder if it is a hack or if this is a valid use
> case for the serialization library. I looked at the asio projects
> example/source, there it was done by using a full archive for each object to
> be transmitted. Sending an archive every time seems a bit expensive too me,
> since a full preamble is sent everytime and I would loose all the pointer
> tracking and other great features from the serialization library.
>
> Regards,
>
> Gerd
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net