Created
January 22, 2017 08:59
-
-
Save payshangjj/6088868bdf1f06b574d7823ab7700e55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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