RPC::PlClient - Perl extension for writing PlRPC clients
require RPC::PlClient;
# Create a client object and connect it to the server my $client = RPC::PlClient->new('peeraddr' => 'joes.host.de', 'peerport' => 2570, 'application' => 'My App', 'version' => '1.0', 'user' => 'joe', 'password' => 'hello!');
# Create an instance of $class on the server by calling $class->new() # and an associated instance on the client. my $object = $client->Call('NewHandle', $class, 'new', @args);
# Call a method on $object, effectively calling the same method # on the associated server instance. my $result = $object->do_method(@args);
PlRPC works by defining a set of methods that may be executed by the client. For example, the server might offer a method ``multiply'' to the client. Now a function call
@result = $client->Call('multiply', $a, $b);
on the client will be mapped to a corresponding call
$server->multiply($a, $b);
on the server. The function calls result will be transferred to the client and returned as result of the clients method. Simple, eh? :-)
$client = eval { RPC::PlClient->new ( ... ) }; if ($@) { print STDERR "Cannot create client object: $@\n"; exit 0; }
The method accepts a list of key/value pairs as arguments. Known arguments are:
Note that you can set or remove encryption on the fly (putting "undef" as attribute value will stop encryption), but you have to be sure, that both sides change the encryption mode.
Example:
use Crypt::DES; $cipher = Crypt::DES->new(pack("H*", "0123456789abcdef")); $client = RPC::PlClient->new('cipher' => $cipher, ...);
Examples:
# Logging to stderr: my $client = RPC::PlClient->new('logfile' => 1, ...);
# Logging to 'my.log': my $file = IO::File->new('my.log', 'a') || die "Cannot create log file 'my.log': $!"; my $client = RPC::PlClient->new('logfile' => $file, ...);
Example:
@results = eval { $client->Call($method, @args }; if ($@) { print STDERR "An error occurred while executing $method: $@\n"; exit 0; }
@results = $cobj->my_method(@args);
will be immediately mapped to a call
@results = $sobj->my_method(@args);
on the server and the results returned to you without any additional programming. Here's how you create $cobj, an instance of RPC::PlClient::Object:
my $cobj = $client->ClientObject($class, 'new', @args);
This will trigger a call
my $sobj = $class->new(@args);
on the server for you. Note that the server has the ability to restrict access to both certain classes and methods by setting $server->{'methods'} appropriately.
#!/usr/local/bin/perl
use strict; # Always a good choice.
require RPC::PlClient;
# Constants my $MY_APPLICATION = "MD5_Server"; my $MY_VERSION = 1.0; my $MY_USER = ""; # The server doesn't require user my $MY_PASSWORD = ""; # authentication.
my $hexdigest = eval { my $client = RPC::PlClient->new ('peeraddr' => '127.0.0.1', 'peerport' => 2000, 'application' => $MY_APPLICATION, 'version' => $MY_VERSION, 'user' => $MY_USER, 'password' => $MY_PASSWORD);
# Create an MD5 object on the server and an associated # client object. Executes a # $context = MD5->new() # on the server. my $context = $client->ClientObject('MD5', 'new');
# Let the server calculate a digest for us. Executes a # $context->add("This is a silly string!"); # $context->hexdigest(); # on the server. $context->add("This is a silly string!"); $context->hexdigest(); }; if ($@) { die "An error occurred: $@"; }
print "Got digest $hexdigest\n";
Copyright (C) 1998, Jochen Wiedmann Am Eisteich 9 72555 Metzingen Germany
Phone: +49 7123 14887 Email: joe@ispsoft.de
All rights reserved.
You may distribute this package under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
An example application is the DBI Proxy client:
DBD::Proxy(3).
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |