Friends can you please tell me how can i send object of a class over a network to the client??

8 Years
Discussion Span
Last Post by mitrmkar
Featured Replies
  • 1

    [QUOTE=Prabakar;648197]I have read about Object Serialization in my JAVA book. Could it be possible with C++?[/QUOTE] See e.g. [URL="http://www.parashift.com/c++-faq-lite/serialization.html"]here[/URL] Read More


On client, send the object just like you would send any other blob, then on client recreate it from the blob. Probably something like below. Make sure the class has an overloaded = operator for this to work.

// server
MyClass object;
send(socketID, &object, sizeof(MyClass));
// client
// this isn't going to be technically accurate, but gives you the idea.
unsigned char* buf = recv(sucketID);
MyObject object = *(MyObject*)buf;

Well, its not quite as easy as what I posted, there is code that I omitted. Also it may be more complex depending on the class objects, such as pointers, other classes, etc.


consider using a textual format (maybe xml).

text is a universal format; it is easy for people to read, write, and edit.
and the network payload is easier to inspect, to modify and to debug.

text data is transparent and help enforce encapsulation between programs.

a textual protocol tends to future-proof your system. one reason is that ranges on numeric fields, padding of members and endianness aren't implied by the format itself. on the other hand, binary formats are platform specific and are difficult to extend.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.