Click here to Skip to main content
13,143,637 members (33,239 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a desktop application that I want to convert to a network apllication i.e client/server application.

Th application has objects of different kinds that encapsulates other objects which encapsulates other objects etc.

Can Send or WSASend send such an object across a connected socket.C
Posted 12-Sep-12 0:45am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can !
But I think, you should not. Because it depends on what kind of data that object holds. The member variables of the class my be holding reference to other object, address to some memory location on your local machine heap, or handle to the file.
e.g. If the object you are transmitting holds any pointer variable, there's no point in building that object by transmitting through socket like you are thinking. Rather you can transmit the relevant information over socket, this way you even can reduce the traffic over the communication channel.

BTW, what's that you wanna achieve by doing this ?
Gbenbam 12-Sep-12 7:49am
My objects do not references to other objects neither pointers to any object or variable, however the member functions contain references and pointers to variable. Is this safe?
Malli_S 12-Sep-12 8:14am
That is safe, but what you wanna achieve by doing this? Because you can send the actual data to build that object again at other end, rather than sending object. Kind of pipe separated values held by the object.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If the objects contain dynamic content like allocated memory or pointers to allocated memory they can't be send. More precise: They can be send but the dynamic members are invalid on the receiving side.

You may split the content into parts that can be re-assembled on the receiving side. This is simple for plain memory blocks by sending an identifier, the size, and the content. But it's getting more complicated for blocks containing dynamic content itself.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

You probably would need a binary or text format in which you will be able to save, and from where you can load the object. The simplest way is using kind of serialization. Try using MFC serialization, or implement your own one. Think about implementing a protocol, or using an existing one, compatible with existing protocols.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100