Soap::Lite is very nice to use, it takes virtually no effort to program a client/server system (i.e. just some ten lines of code if both client and server are implemented in Perl.

Apart from receiving data structures as result from remote methods, you can even operate on remote data structures from the client as if they were local, the only difference being a few lines of code to indicate that they're remote objects.

Below you'll find a Node class (to build a tree with) and a SOAP client and server script to demonstrate this.

Just my 2 cents, -gjb-

Soap server that has the Tree object:
use SOAP::Lite +trace => 'all'; use SOAP::Transport::HTTP; use Node; # don't want to die on 'Broken pipe' or Ctrl-C $SIG{PIPE} = $SIG{INT} = 'IGNORE'; $daemon = SOAP::Transport::HTTP::Daemon -> new (LocalPort => 8080) -> objects_by_reference('Node') -> dispatch_to('Node'); print "Contact to SOAP server at ", $daemon->url, "\n"; $daemon->handle;

Soap client that builds the tree on the server:
use SOAP::Lite +autodispatch => uri => 'urn:', proxy => 'http://localhost:8080/' ; my $root = new Node(12); print $root->toString(), "\n"; for (my $i = 0; $i < 3; $i++) { my $child = new Node($i+1); print $child->toString(), "\n"; $root->addChild($child); print $root->toString(), "\n"; } my $aChild = $root->child(1); my $aParent = $aChild->parent(); print $aParent->toString(), "\n";

and the Node class to build the tree from:
package Node; use strict; sub new { my ($pkg, $value) = @_; my $node = bless { value => $value, parent => undef, nrChildren => 0, children => [] }, $pkg; return $node; } sub addChild { my ($node, $child) = @_; $node->{children}->[$node->{nrChildren}++] = $child; $child->{parent} = $node; } sub numberOfChildren { my ($node) = @_; return scalar(@{$node->{children}}); } sub child { my ($node, $index) = @_; return $node->{children}->[$index]; } sub parent { my ($node) = @_; return $node->{parent}; } sub toString { my ($node) = @_; return "node[$node->{value}]: " . scalar(@{$node->{children}}) . " + children"; } 1;

Note that the client and the server need not run on the same machine as in the example code (this was actually tested).

In reply to Re: Sending data structures via sockets (SOAP) by gjb
in thread Sending data structures via sockets by sawanv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.