Some python scrips for demonstrating chap protocol
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

chap-server.py 889B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python2
  2. from xmlrpc.server import SimpleXMLRPCServer
  3. # Restrict to a particular path.
  4. class RequestHandler(SimpleXMLRPCRequestHandler):
  5. rpc_paths = ('/RPC2',)
  6. # Create server
  7. server = SimpleXMLRPCServer(("localhost", 8000),
  8. requestHandler=RequestHandler)
  9. server.register_introspection_functions()
  10. # Register pow() function; this will use the value of
  11. # pow.__name__ as the name, which is just 'pow'.
  12. server.register_function(pow)
  13. # Register a function under a different name
  14. def adder_function(x,y):
  15. return x + y
  16. server.register_function(adder_function, 'add')
  17. # Register an instance; all the methods of the instance are
  18. # published as XML-RPC methods (in this case, just 'div').
  19. class MyFuncs:
  20. def div(self, x, y):
  21. return x // y
  22. server.register_instance(MyFuncs())
  23. # Run the server's main loop
  24. server.serve_forever()