首页 > Web开发 > 详细

jsonrpc

时间:2018-07-18 19:51:38      阅读:142      评论:0      收藏:0      [点我收藏+]

相关网站: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()
View Code

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)
View Code

4.开防火墙

iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

 

5.现象

技术分享图片

 

jsonrpc

原文:https://www.cnblogs.com/yuanzhenliu/p/9331091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!