Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
 
Share this answer
 
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.
 
Share this answer
 
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 ?
 
Share this answer
 
Comments
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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900