4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
package MyServer;
use RPC::PlServer;
$MyServer::VERSION = '1.0';
@MyServer::ISA = qw(RPC::PlServer);
# Overwrite the Run() method to handle a single connection
sub Run {
my $self = shift;
my $socket = $self->{'socket'};
}
1;
1
2
3
4
5
6
7
8
#!/usr/bin/perl
use MyServer;
my $server = MyServer -> new({'localport'=>'1234',
'pidfile' =>'/home/tvix/server.pid',
}, \@ARGV);
$server->Bind();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
require RPC::PlClient;
# Create a client object and connect it to the server
my $client = RPC::PlClient->new('peeraddr' => 'localhost',
'peerport' => 1234,
'application' => 'server',
'version' => '1.0',
'user' => 'nobody',
'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);
QuoteRefused by server: This is a MyServer server, go away! at /usr/lib/perl5/vendor_perl/5.8.7/RPC/PlClient.pm line 82
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();
};
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";
4 Einträge, 1 Seite |