码迷,mamicode.com
首页 > Web开发 > 详细

jsonrpc

时间:2018-07-18 20:47:24      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:and   hand   gif   closed   iptables   odi   read   pytho   info   

相关网站: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

标签:and   hand   gif   closed   iptables   odi   read   pytho   info   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!