Differences between revisions 7 and 8
Revision 7 as of 2005-04-17 05:59:50
Size: 2502
Editor: aaron
Comment:
Revision 8 as of 2008-11-15 14:00:01
Size: 2512
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 55: Line 55:
 * [http://www.python.org/doc/current/lib/module-SimpleXMLRPCServer.html SimpleXMLRPCServer documentation]
 * [http://www.python.org/doc/current/lib/module-DocXMLRPCServer.html DocXMLRPCServer documentation]
 * [[http://www.python.org/doc/current/lib/module-SimpleXMLRPCServer.html|SimpleXMLRPCServer documentation]]
 * [[http://www.python.org/doc/current/lib/module-DocXMLRPCServer.html|DocXMLRPCServer documentation]]
Line 58: Line 58:
 * [http://sourceforge.net/projects/py-xmlrpc/ Fast C implementation of XML-RPC for python] (only for python version up to 2.2) [http://www.xmlrpc.com/discuss/msgReader$1573 (more notes on it- apparently 20-100x faster!)]  * [[http://sourceforge.net/projects/py-xmlrpc/|Fast C implementation of XML-RPC for python]] (only for python version up to 2.2) [[http://www.xmlrpc.com/discuss/msgReader$1573|(more notes on it- apparently 20-100x faster!)]]
Line 65: Line 65:
This page was based on [http://www.seapig.org/DocXMLRPCServer SeaPig:DocXMLRPCServer,] with BrianDorsey's permission. This page was based on [[http://www.seapig.org/DocXMLRPCServer|SeaPig:DocXMLRPCServer,]] with BrianDorsey's permission.

The DocXmlRpcServer is a very simple XmlRpc server that is also simultaneously a self-documenting web server.

   1 """Demonstration of the Python 2.3 DocXMLRPCServer.
   2 
   3 The demonstration publishes two functions, "message" and "wait."
   4 """
   5 
   6 import time
   7 import socket
   8 
   9 from DocXMLRPCServer import DocXMLRPCServer
  10 
  11 
  12 class SimpleShareServer:
  13     def message(self, msg):
  14         """Print message and return True.
  15 
  16         Log everything passed to this function.
  17         """
  18         print time.asctime(), msg
  19         return True
  20 
  21     def wait(self, seconds):
  22         """Wait a number of seconds, and return the number.
  23 
  24         Wait for a certain number of seconds before returning.
  25         Returns the same number passed in.
  26         """
  27         print time.asctime(), "Waiting %s seconds" % seconds
  28         time.sleep(seconds)
  29         print time.asctime(), "Finished waiting %s seconds" % seconds
  30         return seconds
  31 
  32     
  33 if __name__ == '__main__':
  34     server = DocXMLRPCServer(("", 8000), logRequests=0)
  35     server.register_introspection_functions()
  36     server.register_instance(SimpleShareServer())
  37 
  38     print time.asctime(), 'Application Starting.'
  39     server.serve_forever()
  40     print time.asctime(), 'Application Finishing.'

The benefit of using DocXMLRPCServer is that it automatically creates documentation for your XML-RPC server, just open a browser and head to http://localhost:8000 after starting the server.

Writing a client to call the wait function is left as an exercise for the reader. :)

Resources

Also:

  • AutoXmlRpcServer -- automatically serve modules in local directory with DocXmlRpcServer

Notes

This page was based on SeaPig:DocXMLRPCServer, with BrianDorsey's permission.

Discussion

(none yet!)

DocXmlRpcServer (last edited 2008-11-15 14:00:01 by localhost)

Unable to edit the page? See the FrontPage for instructions.