Application Programming Interface (API)

Contents:

Module bjsonrpc

bjsonrpc is a pure-python module to connect two peers and call remote procedures (RPC). This implementation resembles JSON-RPC 1.1 with several additions that add more interctivity.

You can have a server, which accepts multiple client connections, or a client which is one connection itself.

The implementation is symmetric/bidirectional. That means that the same things you can do with a server and with a client. You could create a client which waits for server requests.

bjsonrpc provides two helper functions to easily create a server or a connection, linked to a socket:

bjsonrpc.createserver(host='127.0.0.1', port=10123, handler_factory=<class 'bjsonrpc.handlers.NullHandler'>)

Creates a bjson.server.Server object linked to a listening socket.

Parameters:

host
Address (IP or Host Name) to listen to as in socket.bind. Use “0.0.0.0” to listen to all address. By default this points to 127.0.0.1 to avoid security flaws.
port
Port number to bind the socket. In Unix, port numbers less than 1024 requires special permissions.
handler_factory
Class to instantiate to publish remote functions.
(return value)
A bjson.server.Server instance or raises an exception.

Servers are usually created this way:

import bjsonrpc

server = bjsonrpc.createserver("0.0.0.0")
server.serve()

Check Module bjsonrpc.server documentation

bjsonrpc.connect(host='127.0.0.1', port=10123, handler_factory=<class 'bjsonrpc.handlers.NullHandler'>)

Creates a bjson.connection.Connection object linked to a connected socket.

Parameters:

host
Address (IP or Host Name) to connect to.
port
Port number to connect to.
handler_factory
Class to instantiate to publish remote functions to the server. By default this is NullHandler which means that no functions are executable by the server.
(return value)
A bjson.connection.Connection instance or raises an exception.

Connections are usually created this way:

import bjsonrpc

conn = bjsonrpc.connect("rpc.host.net")
print conn.call.some_method_in_server_side()

Table Of Contents

Previous topic

HOW-TO’s and examples

Next topic

Module bjsonrpc.server

This Page