python
from SimpleJSONRPCServer import SimpleJSONRPCServer
python
server = SimpleJSONRPCServer(('localhost', 8000))
python
def add(x, y):
return x + y
def multiply(x, y):
return x * y
server.register_function(add)
server.register_function(multiply)
python
server.serve_forever()
python
import json
import requests
def jsonrpc_call(url, method, *params):
payload = {
'jsonrpc': '2.0',
'method': method,
'params': params,
'id': 0,
}
response = requests.post(url, json=payload)
response_data = json.loads(response.content.decode())
return response_data['result']
result = jsonrpc_call('http://localhost:8000', 'add', 3, 5)
result = jsonrpc_call('http://localhost:8000', 'multiply', 4, 2)