dynaic array through sockets(network)

C

Chandra

Hi all,

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.

For Ex:

struct Child
{
a: Int;
b: float;
}


struct parent
{
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
dynamic.

Thanks
 
J

Jim Langston

Chandra said:
Hi all,

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.

For Ex:

struct Child
{
a: Int;
b: float;
}


struct parent
{
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
dynamic.

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.
http://www.parashift.com/c++-faq-lite/serialization.html
 
V

Victor Bazarov

Chandra said:
I have a doubt.

I think it's a question.
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.

For Ex:

struct Child
{
a: Int;
b: float;
}


struct parent
{
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
dynamic.

It is all possible, the only difference is *how* you "pass" it. And
since C++ does not define what a "socket" is, or how one is used, there
is no clear answer to your /question/ in C++ terms. However, you might
find reading about "serialisation" useful. www.google.com

V
 
J

James Kanze

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.

You can't pass structures through a socket interface, period.
All you can pass are bytes (char or unsigned char). Everything
else has to be formatted in accordance with the protocol being
used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top