Hello Mj1234,
You have been long enough on this forum to know how you should post a question and expect an answer. You can not post part of your code and expect as to assist you. Having said that, sample of server code taken from SimpleXMLRPCServer Example.
server.py
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Run the server's main loop
server.serve_forever()
It is easy to see that you have skipped some parts like wrong import of modules and defining your method/function on the script that you provide us sample of code.
Moving to the client side, based on the script above.
client.pl
#!/usr/bin/perl
use strict;
use warnings;
use Frontier::Client;
my $server_url = 'http://localhost:8000/RPC2';
my $server = Frontier::Client->new(url => $server_url);
# Call the remote server and get our result.
my $result = $server->call('pow', 2, 3);
print "Pow: $result\n";
__END__
perl client.pl
Pow: 8
Sample of python script client:
client.py
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8000')
print "Pow: {}".format(s.pow(2, 3))
Run the sample of code and you will see the same output.
Also here is a very nice tutorial Using XML-RPC with Perl, regarding XML-RPC in a variety of languages including Perl.
Update: Not to forget here is the code for server in Perl also, tested with both client and server in Python and Perl.
server.pl
#!/usr/bin/perl
use strict;
use warnings;
use Frontier::Daemon;
sub pow {
my ($x, $y) = @_;
return $x ** $y;
}
# Call me as http://localhost:8000/RPC2
my $methods = {
'pow' => \&pow,
};
Frontier::Daemon->new( LocalPort => 8000,
methods => $methods)
or die "Couldn't start HTTP server: $!";
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
|