in reply to Re: Rapid inter-machine communication on internal network
in thread Rapid inter-machine communication on internal network

I feel kind of lame promoting my own module, but this is what that would look like with RPC::Lite, following the same sort of structure. It's not too much shorter, but it's far more concise and less prone to errors from using the lower-level calls yourself. This example would get a few lines shorter with some of the improvements I have in mind for the API (client construction and response pumping stuff). Note that this code is tested and working.
use RPC::Lite::Client; our @clients; our @server_info; sub setup { foreach my $info (@server_info) { push @clients, RPC::Lite::Client->new({ Transport => "TCP:Host=$info->{host},Port=$info->{port}", # default serializer is JSON, and XML is also available }); } } sub query { my ($what) = @_; my ($responses, $result); # anon sub will be called with any responses from the server foreach my $client (@clients) { $client->AsyncRequest( sub { $responses++; $result += $_[0] }, 'getCount', $what ); } # The API should support aggregating multiple clients so you can # replace the inner foreach with one call, but it doesn't yet. while ($responses < @clients) { foreach my $client (@clients) { $client->HandleResponse; # pump server for data } } return $result; }

Replies are listed 'Best First'.
Re^3: Rapid inter-machine communication on internal network
by sfink (Deacon) on Nov 03, 2006 at 06:43 UTC
    I feel kind of lame promoting my own module, but this is what that would look like with...
    I should probably post this in Meditations rather than burying it here -- but please don't feel lame about something like this (pointing out that you've written a module to solve a problem under discussion). It's one of the primary ways I find out about new modules, or find out what the intent is behind one that I already knew about.

    I'm certainly not going to blame you for helpfully pointing out that you have written some code and released it for me to freely use -- code that happens to implement exactly what I want (or something similar enough that you think it's what I want!)