zoukankan      html  css  js  c++  java
  • 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()
    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.现象

  • 相关阅读:
    自介
    打招呼
    试验四
    作业:实验二
    个人简介
    实验4
    构建之法—心得体会
    作业:实验二
    个人简介
    软件测试第四次博客作业2
  • 原文地址:https://www.cnblogs.com/yuanzhenliu/p/9331091.html
Copyright © 2011-2022 走看看