Discussion:
MFC: TCP/IP and Serialization
(too old to reply)
x***@gmail.com
2013-05-03 09:27:43 UTC
Permalink
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]
2013-05-03 12:52:42 UTC
Permalink
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
2013-05-03 13:53:44 UTC
Permalink
Post by ScottMcP [MVP]
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.
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
2013-05-03 14:55:52 UTC
Permalink
Post by x***@gmail.com
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.
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.
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
Todor Atanasov
2013-05-03 18:43:49 UTC
Permalink
Post by Stephen Wolstenholme
Post by x***@gmail.com
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.
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.
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
I don't need TCP? Can you explain more?
ScottMcP [MVP]
2013-05-03 16:02:49 UTC
Permalink
Post by Todor Atanasov
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
2013-05-03 18:44:28 UTC
Permalink
Post by ScottMcP [MVP]
Post by Todor Atanasov
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.
Thanks I will look in it :)

Loading...