JSON-RPC Calculator¶
The code for this example is located in the examples.calculator.manage
module.
This is a a JSON-RPC server with some simple functions. To run the server type:
python manage.py
Open a new shell and launch python and type:
>>> from pulsar.apps import rpc
>>> p = rpc.JsonProxy('http://localhost:8060')
>>> p.ping()
'pong'
>>> p.functions_list()
[[...
>>> p.calc.add(3,4)
7.0
Implementation¶
The calculator rpc functions are implemented by the Calculator
handler, while the Root
handler exposes utility methods from
the PulsarServerCommands
handler.
-
class
examples.calculator.manage.
Calculator
(subhandlers=None, title=None, documentation=None)[source]¶ A
JSONRPC
handler which implements few simple remote methods.-
rpc_divide
(*args, **kwargs)¶ Divide two numbers.
This method illustrate how to use the
rpc_method()
decorator.
-
rpc_randompaths
(*args, **kwargs)¶ Lists of random walks.
-
-
class
examples.calculator.manage.
Root
(subhandlers=None, title=None, documentation=None)[source]¶ Add two rpc methods for testing to the
PulsarServerCommands
handler.