API Reference¶
-
class
mprpc.
RPCClient
¶ RPC client.
- Usage:
>>> from mprpc import RPCClient >>> client = RPCClient('127.0.0.1', 6000) >>> print client.call('sum', 1, 2) 3
Parameters: - host (str) – Hostname.
- port (int) – Port number.
- timeout (int) – (optional) Socket timeout.
- lazy (bool) – (optional) If set to True, the socket connection is not established until you specifically call open()
- pack_encoding (str) – (optional) Character encoding used to pack data using Messagepack.
- unpack_encoding (str) – (optional) Character encoding used to unpack data using Messagepack.
- pack_params (dict) – (optional) Parameters to pass to Messagepack Packer
- unpack_params (dict) – (optional) Parameters to pass to Messagepack
:param tcp_no_delay (optional) If set to True, use TCP_NODELAY. :param keep_alive (optional) If set to True, use socket keep alive.
Unpacker-
call
()¶ Calls a RPC method.
Parameters: - method (str) – Method name.
- args – Method arguments.
-
close
()¶ Closes the connection.
-
getpeername
()¶ Return the address of the remote endpoint.
-
is_connected
()¶ Returns whether the connection has already been established.
Return type: bool
-
open
()¶ Opens a connection.
-
class
mprpc.
RPCServer
¶ RPC server.
This class is assumed to be used with gevent StreamServer.
Parameters: - pack_encoding (str) – (optional) Character encoding used to pack data using Messagepack.
- unpack_encoding (str) – (optional) Character encoding used to unpack data using Messagepack
- pack_params (dict) – (optional) Parameters to pass to Messagepack Packer
- unpack_params (dict) – (optional) Parameters to pass to Messagepack Unpacker
- Usage:
>>> from gevent.server import StreamServer >>> import mprpc >>> >>> class SumServer(mprpc.RPCServer): ... def sum(self, x, y): ... return x + y ... >>> >>> server = StreamServer(('127.0.0.1', 6000), SumServer()) >>> server.serve_forever()