Differences between revisions 1 and 8 (spanning 7 versions)
Revision 1 as of 2004-04-28 05:58:27
Size: 2643
Editor: dsl254-010-130
Comment: commited from SeaPIG with permission of author
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 1: Line 1:
''The page contents below were copied with permission of author (BrianDorsey) from [http://www.seapig.org/DocXMLRPCServer SeaPig:DocXMLRPCServer]. I'd like to rework the page to fit the form of WorkingWithTime, RssLibraries, etc.,. See also: XmlRpc'' -- LionKimbro [[DateTime(2004-04-28T05:58:27Z)]]


Here is a simple server which implements the above ''message'' procedure as well as a ''wait'' procedure. This server is based on the DocXMLRPCServer included with Python2.3; In Python2.2, use {{{SimpleXMLRPCServer}}} instead, and don't call {{{server.register_introspection_functions()}}}.
The DocXmlRpcServer is a ''very'' simple XmlRpc server that is also simultaneously a self-documenting web server.
Line 8: Line 5:
# ExampleServer.py """Demonstration of the Python 2.3 DocXMLRPCServer.

The demonstration publishes two functions, "message" and "wait."
"""
Line 11: Line 12:
Line 12: Line 14:
Line 15: Line 18:
        """message('Print me!') => True 
        
        Log everything passed to this function"""
        """Print message and return True.

        Log everything passed to this function.
        
"""
Line 22: Line 26:
        """wait(5) => 5
        
        """Wait a number of seconds, and return the number.
Line 25: Line 29:
        Returns the same number passed in."""         Returns the same number passed in.
        
"""
Line 44: Line 49:
Line 46: Line 50:
Line 50: Line 53:
 * http://www.xml-rpc.com/
 * [http://www.python.org/doc/current/lib/module-xmlrpclib.html xmlrpclib 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]
 * Also read the comments in both SimpleXMLRPCServer.py, and DocXMLRPCServer.py - they contain many examples of how to use the modules.
 * [http://sourceforge.net/projects/py-xmlrpc/ Fast C implementation of xmlrpc for python] (only for python version up to 2.2)
 * [http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html Detailed XML-RPC how-to with examples in many languages ]
 * XmlRpc -- general information on XML-RPC
 * BaseHttpServer -- class that DocXmlRpcServer inherits from
 * [[http://www.python.org/doc/current/lib/module-SimpleXMLRPCServer.html|SimpleXMLRPCServer documentation]]
 * [[http://www.python.org/doc/current/lib/module-DocXMLRPCServer.html|DocXMLRPCServer documentation]]
 * {{{SimpleXMLRPCServer.py}}}, and {{{DocXMLRPCServer.py}}} - comments includ many examples of use
 * [[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!)]]

Also:
 * AutoXmlRpcServer -- automatically serve modules in local directory with DocXmlRpcServer

== Notes ==

This page was based on [[http://www.seapig.org/DocXMLRPCServer|SeaPig:DocXMLRPCServer,]] with BrianDorsey's permission.

= Discussion =

(none yet!)

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.