Mj1234 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have created an xmlrpc server with a python script and have two functions registered as shown.

import xmlrpclib server = SimpleXMLRPCServer(("localhost", 8000)) print ("Listening on port 8000...") server.register_function(read_symbol,"read_symbol") server.register_function(write_symbol,"write_symbol") server.serve_forever()

I now try to connect to this sever through my Perl client.

use Frontier::Client; $client = Frontier::Client->new(url =>"http://localhost:8000"); return $client->call('read_symbol',$variable);

This unfortunately returns me "Fault returned from XML RPC Server, fault code 1: <type 'exceptions.ValueError'>:cannot uniquely identify symbol". However a Python client is able to connect and get the response. Can someone let me know what could be wrong?

Replies are listed 'Best First'.
Re: Perl RPC Client
by poj (Abbot) on Mar 16, 2018 at 07:48 UTC

    Try turning on debug

    $client = Frontier::Client->new(url =>"http://localhost:8000", debug => 1);

    What is in $variable ?

    poj
      $variable has the global whose value I need to fetch.
Re: Perl RPC Client
by thanos1983 (Parson) on Mar 16, 2018 at 10:18 UTC

    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!