I run an open source project that was started in Java, but for performance considerations I am re-writing in C++. With Java it was easy to implement an object-oriented client-server communication model which passed self-extracting classes between sockets. There was a "virtual" base class that specified a method to perform the unpacking. To create a type of message (lets say sending a username and a message) I would create a new serializable class with the needed variables and implement the unpacking function as needed. To send the data I would create that new class and send it to the socket. To recieve, I would read in an object of the base class type from the socket and call that "virtual" function to unpack: Java took care of all the serialization and type handling.

I'm having trouble planning this in C++. I was able to create the base-class and sub-classes and emulate serialization using overloaded stream operators. The problem is that I cannot figure out how to read the data from the socket, figure out what type of object I recieved and call the correct unpack function.

I havn't used C++ in a long time and i'm a little rusty, so its taking me a while to get used to inheritance and type changing.

Could anyone offer any suggestions or point me in the right direction? This project is very important to me and this change to C++ will really make this project usable. If you want to check out the project idea, you can visit our homepage

Any help would be *greatly* appreciated. Thanks!