Sockets and structures?
hi, i'm wondreing if using asio library can i send a structure and not just string messages using the boost::asiio:write command? or how could i do to send a structure which have many information fields? thanks -- Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain
On Fri, Sep 25, 2009 at 4:56 AM, pedro chaparro
hi, i'm wondreing if using asio library can i send a structure and not just string messages using the boost::asiio:write command? or how could i do to send a structure which have many information fields? thanks
As long as it is a POD without pointers, just give it the pointer to the beginning of it and the size. If it is not POD and/or has pointers, then send each element individually.
OvermindDL1 wrote:
On Fri, Sep 25, 2009 at 4:56 AM, pedro chaparro
wrote: hi, i'm wondreing if using asio library can i send a structure and not just string messages using the boost::asiio:write command? or how could i do to send a structure which have many information fields? thanks
As long as it is a POD without pointers, just give it the pointer to the beginning of it and the size. If it is not POD and/or has pointers, then send each element individually.
Or use Boost.Serialization to serialize your struct/class to a text archive and stream that with asio.
On Fri, Sep 25, 2009 at 10:14 AM, Nat Goodspeed
Or use Boost.Serialization to serialize your struct/class to a text archive and stream that with asio.
Boost.Serialization is good if you are going to serialize up vast hierarchies with lots of pointers that can be self referencing and such, but it tends to be very costly in execution speed. Something like Boost.Spirit2.1 can serialize things up to a binary format as well, and *very* fast. Although something like Google's open source message system could serialize up messages even better (we need a Boost implementation of that system... hmm...).
On Sep 25, 2009, at 3:56 AM, pedro chaparro wrote:
hi, i'm wondreing if using asio library can i send a structure and not just string messages using the boost::asiio:write command? or how could i do to send a structure which have many information fields? thanks
Hi Pedro, For anything that doesn't involve pointers you could take a look at Thrift at http://incubator.apache.org/thrift/ Thrift supports lightweight cross-language and cross-platform RPC, as well as serialization to files. The standard release is POSIX only, but I've added a Boost/Asio based port to Windows that's currently available as a patch. - Rush
participants (4)
-
Nat Goodspeed
-
OvermindDL1
-
pedro chaparro
-
Rush Manbert