Skip to content

Instantly share code, notes, and snippets.

@payshangjj
Created January 22, 2017 09:00
Show Gist options
  • Save payshangjj/68d04cf7ec4148b4b8a76af981b1463e to your computer and use it in GitHub Desktop.
Save payshangjj/68d04cf7ec4148b4b8a76af981b1463e to your computer and use it in GitHub Desktop.
from SimpleXMLRPCServer import SimpleXMLRPCServer
def add(x, y):
return x + y
if __name__ == '__main__':
s = SimpleXMLRPCServer(('127.0.0.1', 8080))
s.register_function(add)
s.serve_forever()
s是一个绑定了本地8080端口的服务器对象,register_function()方法将函数add注册到s中。serve_forever()启动服务器。
再给个客户端client.py:
from xmlrpclib import ServerProxy
if __name__ == '__main__':
s = ServerProxy("http://127.0.0.1:8080")
print s.add(3,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment