Re: dynaic array through sockets(network)
"Chandra" <email@example.com> wrote in message
I have a doubt.
If I have 2 structures and one is parent of other , ie the child
structure is present in the parent one . And if the child structure is
declared as dynamic array in the parent , will it be possible to pass
the parent structure thru network using sockets onto other application
running on different system provided the API is known to both the
sender and the receiver.
c : Int;
d : array of Child;(dynamic array)
If I make it static array, I will be able to pass it, but wat if it is
You need to serialize it. Consider, when you send data over sockets the
size of the data needs to be known by the receiving end. For a structure it
would be the size of the structure, which is constant. However. Other data
that the structure points to is not constant. Consider attempting to pass a
std::string (or dynamic char array) over sockets. The receiving end needs
to know when to stop receiving the string.
A common way is to send the size of the data first followed by the data.
The receiving end then first receives the size of the string, then it knows
when the string is finished.
So, for your dynamic array, you would wend to tell the receiving end the
size of the dynamic data.
Please refer to the C++ FAQ chapter 36: Serialization and Unserialization.