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

Hi all, I am trying to use RPC::XML to send request to a server and get back the result as response. But i get the following error when executing a small addition program. I have already installed perl web server in port:80. My program is as follows:
#!/usr/bin/perl # Testing sum() use strict; use warnings; use RPC::XML::Client; sub sum { my ($args1,$args2) = @_; print "inside sum"; return $args1 + $args2; } my @args = (9,9); print "The numbers to be added are :@args\n"; my $client = new RPC::XML::Client 'http://lovalhost:80'; my $req = RPC::XML::request->new('sum', @args); my $res = $client->send_request($req); print "The result is : $res";
I get the following error as result.
The numbers to be added are :9 9 The result is : syntax error at line 1, column 54, byte 54: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> =====================================================^ <HTML> at C:/Perl/site/lib/RPC/XML/Client.pm line 394
As i am newbie in perl i am not able to figure out the reason for the error.Please help me out in rectifying this one. The main aim is to integrate perl and JAVA.That is the reason i am in need of RPC::XML.... Thanks in advance, Aishu

Replies are listed 'Best First'.
Re: RPC::XML error
by ikegami (Patriarch) on Mar 25, 2010 at 05:27 UTC
    Sounds like http://lovalhost:80 (shouldn't that be localhost) returns HTML, and that sounds wrong for something called RPC::XML.
      ya sorry that is localhost. If its wrong then in what format should the output be sent and how?
        You need an RPC server that takes an RPC request, executes it and returns an RPC response.
Re: RPC::XML error
by Khen1950fx (Canon) on Mar 25, 2010 at 06:46 UTC
    I couldn't get RPC::XML::Client to work right, so I used Frontier::Daemon instead:
    #!/usr/bin/perl use strict; use warnings; use Frontier::Daemon; my $d = Frontier::Daemon->new( methods => { sum => \&sum }, LocalAddr => '127.0.0.1', LocalPort => 1080, ); sub sum { my @args = (9, 9); print "The numbers to be added are: @args\n"; return $args[0] + $args[1], "\n"; }

    Update: I used WebService::Advogato by jaldhar to make a simple sum, product, and square client:

    #!/usr/bin/perl #sum, product, square use strict; use warnings; use Data::Dumper::Concise; use WebService::Advogato; my $client = new WebService::Advogato(); my $int_x = '91'; my $int_y = '23'; warn Dumper($client->sumprod($int_x, $int_y)); warn Dumper($client->square($int_x));

      Why would a deamon (server) be a replacement for a client?

      Is the last line garbage (never executed), or is that code the same as

      #!/usr/bin/perl use strict; use warnings; sub sum { my @args = (9, 9); print "The numbers to be added are: @args\n"; return $args[0] + $args[1], "\n"; } print "The sum is: ", sum(), "\n";
        ikegami, The last line do gets executed since you are calling the sub routine only there.
      hi Khen1950fx, Thanks for your reply. It worked fine....!!!! great job.. ~Aishu