服务端代码
from xmlrpc.server import SimpleXMLRPCServer
def speak_your_words(s):
print("message from client:", s)
return "message from server: " + s
server = SimpleXMLRPCServer(("localhost",9999)) # 绑定端口
server.register_function(speak_your_words) # 注册函数
server.serve_forever() #启动监听
客户端代码:
from xmlrpc.client import ServerProxy
s = ServerProxy("http://localhost:9999")
x=s.speak_your_words("chris")
print(x)
服务端输出:
message from client: chris
127.0.0.1 - - [20/Nov/2019 21:04:50] "POST /RPC2 HTTP/1.1" 200 -
客户端输出:
message from server: chris
参考:https://blog.csdn.net/m0_37422289/article/details/82840504