WHat is the best way to send C++ classes over TCP/IP?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: WHat is the best way to send C++ classes over TCP/IP?

  1. #1
    Join Date
    Mar 2009
    Posts
    166

    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    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.

  3. #3
    Join Date
    Mar 2009
    Posts
    166

    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.

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center