I've trawled the internet searchiing for an explaination on how to do this.

I'm working on an assignment and we are told to "transmit a whole object to the server".

As far as I know, the send function of winsock2 only allows you to send data of type char, so how can you transmit an object? Is there a way to convert an object to type char and then convert it back to an object the other end?

I'm at a loss here!

All data in a digital computer is bits and bytes, effetively 0/1 strings. Datatypes of any sort are just interpretations of these data. Your job here is to serialise your object into a string of bytes before transmittions and recreate the object after it has been transmitted. Easiest to understand is probably the following: Write all the member variables of your object into a character-string (using string stream operators or sprintf, or whatever method you are familiar with). This way you have serialised the object into char's. Transmit this string and at the receiving end read the values back into memory and create an object using those values.
You have to think about what you want to do in case your object has complex members and/or pointers to other objects, but the general approach is the same.
Obviously this method is not very efficient, but once you've done it this way you can think about ways to improve permance.
Also you can have a look at the boost serialisation library if you are interested.
http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/index.html

All data in a digital computer is bits and bytes, effetively 0/1 strings. Datatypes of any sort are just interpretations of these data. Your job here is to serialise your object into a string of bytes before transmittions and recreate the object after it has been transmitted. Easiest to understand is probably the following: Write all the member variables of your object into a character-string (using string stream operators or sprintf, or whatever method you are familiar with). This way you have serialised the object into char's. Transmit this string and at the receiving end read the values back into memory and create an object using those values.
You have to think about what you want to do in case your object has complex members and/or pointers to other objects, but the general approach is the same.
Obviously this method is not very efficient, but once you've done it this way you can think about ways to improve permance.
Also you can have a look at the boost serialisation library if you are interested.
http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/index.html

Ah, I hadn't heard or thought of this concept!

I was just thinking about it the wrong way.

Thanks! The info was really helpful :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.