Thread Frage zum Modul PlRPC (3 answers)
Opened by tvix2006 at 2006-05-14 12:39

esskar
 2006-05-15 01:03
#37256 #37256
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
server

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -wT
# Note the -T switch! This is always recommended for Perl servers.

use strict; # Always a good choice.

require RPC::PlServer;
require MD5;


package MD5_Server; # Clients need to request application
# "MD5_Server"

$MD5_Server::VERSION = '1.0'; # Clients will be refused, if they
# request version 1.1
@MD5_Server::ISA = qw(RPC::PlServer);

eval {
# Server options below can be overwritten in the config file or
# on the command line.
my $server = MD5_Server->new({
'pidfile' => '/var/run/md5serv.pid',
'configfile' => '/etc/md5serv.conf',
'facility' => 'daemon', # Default
'user' => 'nobody',
'group' => 'nobody',
'localport' => 2000,
'logfile' => 0, # Use syslog
'mode' => 'fork', # Recommended for Unix
'methods' => {
'MD5_Server' => {
'ClientObject' => 1,
'CallMethod' => 1,
'NewHandle' => 1
},
'MD5' => {
'new' => 1,
'add' => 1,
'hexdigest' => 1
},
}
});
$server->Bind();
};


client

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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";

View full thread Frage zum Modul PlRPC