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-
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;
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";
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;
In reply to Re: Sending data structures via sockets (SOAP)
by gjb
in thread Sending data structures via sockets
by sawanv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |