-
February 28th, 2012, 03:02 PM
#1
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?
Regards,
Ellay K.
-
February 28th, 2012, 03:23 PM
#2
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.
-
February 28th, 2012, 03:50 PM
#3
Re: WHat is the best way to send C++ classes over TCP/IP?
By shared library, do you mean a DLL? If not, can you point me to an example using that approach?
Regards,
Ellay K.
-
February 29th, 2012, 12:53 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|