Some python scrips for demonstrating chap protocol
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

chap-server.py 942B

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