惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
P
Proofpoint News Feed
P
Privacy International News Feed
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
S
Securelist
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
GbyAI
GbyAI
B
Blog RSS Feed
A
About on SuperTechFans
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyberwarzone
Cyberwarzone
I
Intezer
T
Tor Project blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
D
DataBreaches.Net
U
Unit 42
Project Zero
Project Zero
Martin Fowler
Martin Fowler
V
V2EX
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V2EX - 技术
V2EX - 技术
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tenable Blog
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Latest news
Latest news
Webroot Blog
Webroot Blog

博客园 - 哈哈

cas服务器搭建后的调整 使用python直接连接http服务器获取数据 request的url地址 numpy的多项式函数与求导 pandas相关 tcp与ip的包结构 江苏铁路 易经-64卦 图书分类-中图法,值得一看的图书 linux时区,curl的使用,nginx日志,watch 使用selenium模仿登录,执行js python与java的交互 计算斐波那契数列 Python线程 selenium的使用 pip使用 python读取postgresql 18位身份证的验证码 python读取docx文件属性-最后一次保存的时间等
使用python实现rpc服务
哈哈 · 2021-03-13 · via 博客园 - 哈哈

一种是使用xmlrpc

server端:

from xmlrpc.server import SimpleXMLRPCServer
class RPCServer(object):

    def __init__(self):
        super(RPCServer, self).__init__()
        self.send_data = 'hello world'
        self.recv_data = None

    def getObj(self):
        return self.send_data

    def sendObj(self, data):
        self.recv_data = data

# SimpleXMLRPCServer
server = SimpleXMLRPCServer(('localhost',9999), allow_none=True)
server.register_introspection_functions()
server.register_instance(RPCServer())
server.serve_forever()

client端:

import time
from xmlrpc.client import ServerProxy

# SimpleXMLRPCServer
def xmlrpc_client():
    c = ServerProxy('http://localhost:9999')
    a=c.getObj()
    print(a)
    c.sendObj(a)


if __name__ == '__main__':
    xmlrpc_client()

还有一种是使用zerorpc,性能较高

server端:

import zerorpc

class RPCServer(object):

    def __init__(self):
        super(RPCServer, self).__init__()
        self.send_data = 'helloworld'
        self.recv_data = None

    def getObj(self):
        return self.send_data

    def sendObj(self, data):
        self.recv_data = data

s = zerorpc.Server(RPCServer())
s.bind('tcp://127.0.0.1:8888')
s.run()

client端:

import zerorpc
import time


def client():
    c = zerorpc.Client()
    c.connect('tcp://127.0.0.1:8888')
    a=c.getObj()
    print(a)
    c.sendObj(a)


if __name__ == '__main__':
    client()