Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MFC: TCP/IP and Serialization

66 views
Skip to first unread message

xum...@gmail.com

unread,
May 3, 2013, 5:27:43 AM5/3/13
to
Hi guys,
I have a program that I want to split into a server and client. The server to make the heavy calculations and the client just to use the ready data.

So my first question is how to do it:
1. Simple string TCP/IP sending some custom protocol
2. Serialization and then via TCP/IP

The problem with 1 is that it will be very complicated because I have a class with the result of the calculations in which I have int, CString, CArray, and class objects which in them self also have CArrays. So making all that in a string protocol is near impossible.

So I am leaning for method 2. But I have 0 experience with serialization. If I want to serialize the class that contains the result, can I just serialize it, or I have to serialize all sub classes also/variables too? And how to do it?


Also which method is faster, as I am reading that serialization is a bit slow.

ScottMcP [MVP]

unread,
May 3, 2013, 8:52:42 AM5/3/13
to
The MFC serialization is a framework for doing this if (and only if) all of the classes and subclasses you are using are derived from CObject. Each such class has a Serialize method. To serialize a complex class you must override its Serialize method and invoke the Serialize method of all its sub classes. So it is a "framework" but not a total solution.

The advantage MFC's framework gives you over doing everything yourself is that MFC has already defined the "custom format" that is used in the messages. So you don't have to do the formatting and de-formatting part. But you do have to write the Serialize method for every class and sub class that has multiple data members.

For an example of doing this see the MFC sample DRAWCLI in the MSDN library.

The speed of serialization is going to be about the same whether you use your own format or MFC's. It's an inherently low-level process that must deal with everything byte-by-byte.

Another possible solution might be to use a separate thread instead of a separate process. With a "server thread" you do not have to do serialization at all since both threads can access the same data structures.

Todor Atanasov

unread,
May 3, 2013, 9:53:44 AM5/3/13
to
Thanks for the reply.
The thread will not work because the server needs to be on a separated machine, thus I need the TCP/IP (the "server" now works on separated thread, but I need it on separate PC).


I will look in the MSDN library thank you. But where can I see some examples for serialization/de-serialization of complex classes, because every example I could find is with two variables and ">>" "<<" operators :)

Stephen Wolstenholme

unread,
May 3, 2013, 10:55:52 AM5/3/13
to
I am assuming you want the server and the client on different
hardware. Why do you want TCP as you only need IP?

Steve

--
EasyNN-plus. Neural Networks plus. http://www.easynn.com
SwingNN. Forecast with Neural Networks. http://www.swingnn.com
JustNN. Just Neural Networks. http://www.justnn.com

ScottMcP [MVP]

unread,
May 3, 2013, 12:02:49 PM5/3/13
to
>> I will look in the MSDN library thank you. But where can I
>> see some examples for serialization/de-serialization of
>> complex classes, because every example I could find is
>> with two variables and ">>" "<<" operators

DRAWCLI is such an example. It serializes arrays of complex objects to file, and also serializes to clipboard.


Todor Atanasov

unread,
May 3, 2013, 2:43:49 PM5/3/13
to
03 май 2013, петък, 17:55:52 UTC+3, Stephen Wolstenholme написа:
I don't need TCP? Can you explain more?

Todor Atanasov

unread,
May 3, 2013, 2:44:28 PM5/3/13
to
Thanks I will look in it :)
0 new messages