About Transfering Complex datastructures using Sockets

S

sareel

I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...
 
M

Morris Dovey

(e-mail address removed) (in
(e-mail address removed)) said:

| I need the explanation/code to transmit a complex datastructure like
| Linked list or binary tree
| using sockets from client to sever...

Not terribly difficult - just decide how you plan to parse the list or
tree, what (symbolic?)representation makes sense for the pointers and
the specifics of your protocol for passing a single element. Once
that's done, all you need to do is write the code to implement what
you've specified.

If you have difficulties with the C coding part of the problem, look
for help here. :)
 
R

Roberto Waltman

I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...

<Off-topic>
In the general case, transfer the elements individually and rebuild
the data structure in the receiving end.
(There may be shortcuts in some particular scenarios.)
Try posting again in comp.programming
</Off-topic>
 
F

Flash Gordon

I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...

Then write serialisers and deserialisers and read up on the socket
implementation for your platforms of interest. Alternatively, use a
language that has all this built in.
 
D

deepak

I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...

Use sprintf() and store into a character array and transfer through
sockets.
Do the reverse in the receiving side.

That what i'm doing to avoid big-endian and little endian problems.
 
T

Tom St Denis

deepak said:
Use sprintf() and store into a character array and transfer through
sockets.
Do the reverse in the receiving side.

That what i'm doing to avoid big-endian and little endian problems.

what about if the two machines don't use your character encoding?

Hint: this is why things like ASN.1 were invented.

Tom
 
K

Keith Thompson

deepak said:
Use sprintf() and store into a character array and transfer through
sockets.
Do the reverse in the receiving side.

That what i'm doing to avoid big-endian and little endian problems.

Linked lists and binary trees include pointers. Pointers can be
converted to strings with sprintf, and back again with sscanf, but the
values will be meaningless on the receiving side. In the general
case, you'll need to map pointer values to some kind of index, then
allocate the individual nodes on the other end and re-map the indexes
back to pointers.
 
N

Nelu

I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...

If you find a way to serialize and deserialize the information
contained in the nodes then you can use either XML or, easier to use,
LISP syntax to send the information along with the structure.

A
/ \
B C
/ \ / \
D E F G

The above structure can be sent as:

(A (B (D E)) (C (F G)))

You can run into problems if you have ( and ) as part of the
information in the nodes. If you escape those characters or if you
encode all the information in the nodes to use printable characters
except for '(' and ')' in a specific encoding you should be safe and
have an almost portable protocol.
Check uuencode and uudecode for hints.
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top