WHat is the best way to send C++ classes over TCP/IP?
Hello,
I have a custom TCP/IP librrary and I want to send complete C++ classes over the socket to another application. I am worried about all the normal issues such as endianess, structure padding, etc. Is there a good library that abstracts these details?
Re: WHat is the best way to send C++ classes over TCP/IP?
It's not a good idea to send objects between programs through sockets, for the reasons you specified. There are two solutions I would suggest.
1) Serialize your data and send that instead. Turn the object into XML/JSON and send it across the socket and have the other application unserialize it. JSON is lighter weight.
2) Used a shared library for both applications, let the library handle the creation and such, and you should be able to pass it to another application using the same library.
Re: WHat is the best way to send C++ classes over TCP/IP?
Yes, I mean a dll.
Just a note though, I'm not entirely sure how things like vtables and pointers will act. The two programs are in separate process space, so classes made of PODs would be best.
I recommend serialization myself, that's how servers talk to each other, programs listening to sockets are like servers.
Bookmarks