| Author |
About Transfering Complex datastructures using Sockets
|
|
| sareel@gmail.com 2006-06-28, 7:58 am |
| I need the explanation/code to transmit a complex datastructure like
Linked list or binary tree
using sockets from client to sever...
| |
| Morris Dovey 2006-06-28, 6:56 pm |
| sareel@gmail.com (in
1151502345.227672.158000@y41g2000cwy.googlegroups.com) 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. :-)
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
| |
| Roberto Waltman 2006-06-28, 6:56 pm |
| sareel@gmail.com wrote:
>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>
| |
| Flash Gordon 2006-06-28, 6:56 pm |
| sareel@gmail.com wrote:
> 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.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
| |
| deepak 2006-06-28, 6:56 pm |
|
sareel@gmail.com wrote:
> 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.
| |
| Tom St Denis 2006-06-28, 6:56 pm |
|
deepak wrote:
> sareel@gmail.com wrote:
>
> 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
| |
| Keith Thompson 2006-06-28, 6:56 pm |
| "deepak" <deepakpjose@gmail.com> writes:
> sareel@gmail.com wrote:
>
> 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.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
| |
|
| sareel@gmail.com writes:
> 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.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
|
|
|
|