[python-win32] XML-RPC example - was beginner's question on network programming

Tyler Mitchell TMitchell at lignum.com
Thu Dec 4 19:51:31 EST 2003






Mark, what you didn't say was: "Contribute back you silly goose".  I should
have thought of that a while ago, thanks for the reminder!
I was kinda holding out waiting for someone else to point out a better link
or say they've already got it figured already ;)

So here's an example of what I've done:

Pre-requisites include xmlrpclib and SimpleXMLRPCServer libraries.  Let me
know if you need a hand finding them.

----------
Here's the server-side script, keeping it in an order usual for tutorial
purposes:

>>>class MyFuncs:
>>>  def add(self, x, y):
>>>    return x + y

>>>from SimpleXMLRPCServer import SimpleXMLRPCServer
>>>server = SimpleXMLRPCServer((localhost,8000))
>>>server.register_instance(MyFuncs())
# The server will run until you hit Control-C or the like

---------
Here's the client-side script to access above said function:

>>>from xmlrpclib import Server
>>>myserver = Server("http://localhost:8000")
>>>print myserver.add(5,6)
11  #Printed results here, but could also pass the object (?) back as
well...

>>>mytotal = myserver.add(5,6)
>>>print mytotal
11





                                                                           
             "Mark Hammond"                                                
             <mhammond at skippin                                             
             et.com.au>                                                 To 
             Sent by:                  "'Tyler Mitchell'"                  
             python-win32-boun         <TMitchell at lignum.com>              
             ces at python.org                                             cc 
                                       python-win32 at python.org             
                                                                    Fax to 
             12/04/2003 03:12                                              
             PM                                                    Subject 
                                       RE: [python-win32] beginner's       
                                       question on network programming     
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




> I should say, I found the documentation of XML-RPC, specifically for
> python, to be sketchy and irritating from a new user
> perspective.  So I
> suggest you don't waste your time reading until you've found a good
> tutorial.  I was barely able to find a good server example of
> xml-rpc in
> python!  If you or others on the list would like, I could
> walk you through
> my  most simple application as a tutorial.

As a side note, most of the Python/extensions docs follow this cycle:
* Technically smart person writes cool code, and very sketchy docs
(generally written for someone just like him/her)
* 500 people scratch their head, stumble around, post to mailing lists and
manage to put together a vague answer.  Many fail.
* One of the 500 picks up the ball and contributes real documentation.
* The next 500 people trying to use it have a much better life.

This is, unfortunately, the current nature of Open Source.  As Open Source
moves up the food chain, I hope to see that change, but it won't be soon.

While it may seem formidable, submitting docs and examples needn't be that
hard, and will generally be gratefully accepted.

Mark.


_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32





More information about the Python-win32 mailing list