jsonrpc
Posted yuanzhenliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jsonrpc相关的知识,希望对你有一定的参考价值。
相关网站:https://pypi.org/project/python-jsonrpc/
1.安装
pip install python-jsonrpc
2.服务端
#!/usr/bin/env python # coding: utf-8 import pyjsonrpc class RequestHandler(pyjsonrpc.HttpRequestHandler): @pyjsonrpc.rpcmethod def add(self, a, b): """Test method""" return a + b # Threading HTTP-Server http_server = pyjsonrpc.ThreadingHttpServer( server_address = (\'45.77.10.62\', 8080), RequestHandlerClass = RequestHandler ) print "Starting HTTP server ..." print "URL: http://localhost:8080" http_server.serve_forever()
3.客户端
#!/usr/bin/env python # coding: utf-8 import pyjsonrpc http_client = pyjsonrpc.HttpClient( url = "http://45.77.10.62:8080", username = "", password = "" ) print http_client.call("add", 1, 2) # Result: 3 # It is also possible to use the *method* name as *attribute* name. print http_client.add(1, 2) # Result: 3 # Notifications send messages to the server, without response. http_client.notify("add", 3, 4)
4.开防火墙
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
5.现象
以上是关于jsonrpc的主要内容,如果未能解决你的问题,请参考以下文章