| AnyEvent::JSONRPC::TCP::Server - Simple TCP-based JSONRPC server |
AnyEvent::JSONRPC::TCP::Server - Simple TCP-based JSONRPC server
use AnyEvent::JSONRPC::TCP::Server;
my $server = AnyEvent::JSONRPC::TCP::Server->new( port => 4423 );
$server->reg_cb(
echo => sub {
my ($res_cv, @params) = @_;
$res_cv->result(@params);
},
sum => sub {
my ($res_cv, @params) = @_;
$res_cv->result( $params[0] + $params[1] );
},
);
This module is server part of the AnyEvent::JSONRPC manpage.
Create server object, start listening socket, and return object.
my $server = AnyEvent::JSONRPC::TCP::Server->new(
port => 4423,
);
Available %options are:
Listening port or path to unix socket (Required)
Bind address. Default to undef: This means server binds all interfaces by default.
If you want to use unix socket, this option should be set to "unix/"
Error callback which is called when some errors occurred. This is actually the AnyEvent::Handle manpage's on_error.
EOF callback. same as the AnyEvent::Handle manpage's on_eof callback.
Hashref options of the AnyEvent::Handle manpage that is used to handle client connections.
Register JSONRPC methods.
$server->reg_cb(
echo => sub {
my ($res_cv, @params) = @_;
$res_cv->result(@params);
},
sum => sub {
my ($res_cv, @params) = @_;
$res_cv->result( $params[0] + $params[1] );
},
);
JSONRPC callback arguments consists of $result_cv, and request @params.
my ($result_cv, @params) = @_;
$result_cv is the AnyEvent::JSONRPC::CondVar manpage object.
Callback must be call $result_cv->result to return result or $result_cv->error to return error.
If $result_cv->is_notification() returns true, this is a notify request
and the result will not be send to the client.
@params is same as request parameter.
Daisuke Murase <typester@cpan.org>
Copyright (c) 2009 by KAYAC Inc.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| AnyEvent::JSONRPC::TCP::Server - Simple TCP-based JSONRPC server |