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

Tyler Mitchell TMitchell at lignum.com
Tue Dec 16 11:58:54 EST 2003






For those of you who may have tried out my earlier example...sorry.  It's
ripe with errors!
Here's some fixes and a better summary examples without (as many?)
problems.  I'd love to know if you try it out at all.

Tyler

---------------
Here's the errors.....

> >>>from SimpleXMLRPCServer import SimpleXMLRPCServer
> >>>server = SimpleXMLRPCServer((localhost,8000))

Host should be quoted:
>>>server = SimpleXMLRPCServer(("localhost",8000))

> >>>server.register_instance(MyFuncs())
> # The server will run until you hit Control-C or the like

No it wont, my comment is a lie - in fact the server won't run at all!  I
didn't issue the final command:
>>>server.serve_forever()
And on some platforms, Control-C won't kill.  I.e. on Windows you must use
Control-Pause (aka Break).

So to clarify, the following is the full example including above
comments/fixes:

-------------------------------------

Here's the server-side script, not it makes the functions in a class called
MyFuncs available.  MyFuncs must already exist.
>>>from SimpleXMLRPCServer import SimpleXMLRPCServer
>>>server = SimpleXMLRPCServer(("localhost",8000))
>>>server.register_instance(MyFuncs())
>>>server.serve_forever()

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




More information about the Python-win32 mailing list