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; }