Sending objects through sockets

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
shoo
Earned a small fee
Earned a small fee
Posts: 14
Joined: Fri Jun 17, 2005 10:14 am

Sending objects through sockets

Post by shoo » Wed Jul 20, 2005 2:22 pm

Hey !

I developped a server / client (console only, without events) and I'll need to send objects through the wxSockets.

But the class my objects are issued from contains several wxString fields. I suppose the objects won't have the same size, and I'll have a few difficulties casting it on arrival... And those wxStrings must be managed as pointers... argh !

Got a hint ? Thanks in advance :)

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Wed Jul 20, 2005 4:23 pm

The process of doing this is called serialization. It means you have to convert your object into a stream of data, that can be read back later. C++ does not have built-in support for this, so you need to implement it yourself.

It will also be very handy when you need to save objects to disk, since the process is pretty much the same. One hint is to design your fileformat first, then send this data through the socket.

One thing to keep in mind is that you can't serialize any "not solid" data like pointers.

Game_Ender
Knows some wx things
Knows some wx things
Posts: 45
Joined: Wed Jun 15, 2005 5:47 pm

Post by Game_Ender » Thu Jul 21, 2005 7:55 pm

You could use boost's serialization library. It does have support for serializing objects that have pointers.

shoo
Earned a small fee
Earned a small fee
Posts: 14
Joined: Fri Jun 17, 2005 10:14 am

Post by shoo » Fri Jul 22, 2005 3:31 pm

Thanks, I knew about serialization (coded a bit in Java) but I just hoped to find a magical wx formula or something :wink:
Boost seems a bit hard to implement.

So, I serialized my objects with home-made methods - seems to work pretty well :D

Post Reply