root@localhost ~# cat /usr/lib/perl5/site_perl/5.8.8/MyApp/Test.pm#!/usr/bin/perl #-------------------------- # In your application class package MyApp; sub own_method { # called by clients my ($server, @params) = @_; # $server is JSONRPC object. return 5; # return a scalar value or a hashref or an arryaref. } 1;
root@localhost ~# cat /usr/local/bin/server.pl#!/usr/bin/perl use JSONRPC::Transport::HTTP; use MyApp; # a la XMLRPC::Lite JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle();
root@localhost ~# cat /usr/local/bin/client.pl#!/usr/bin/perl ################## # Daemon version # ################## use strict; use lib qw(. ./lib); use JSONRPC::Transport::HTTP; my $daemon = JSONRPC::Transport::HTTP::Daemon ->new(LocalPort => 8080) ->dispatch_to('MyApp/Test'); $daemon->handle();
I get the following output from the client:#!/usr/bin/perl use JSONRPC::Transport::HTTP; my $uri = 'http://127.0.0.1:8080/MyApp/Test/'; my $res = JSONRPC::Transport::HTTP ->proxy($uri) ->call('echo',['This is test.']) ->result; if($res->error){ print $res->error,"\n"; } else{ print $res->result,"\n"; } # or my $client = JSONRPC::Transport::HTTP->proxy($uri); print $client->echo('This is test.'); # the alias, _echo is same.
[root@localhost ~]# client.pl 64 0 No such a method. 64 0
[root@localhost ~]# server.pl [root@localhost ~]# server.pl Status: 500 Content-Type: text/plain; charset=UTF-8
In reply to json help request by btoovey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |