Setting up test for XML-RPC

M

Moosebumps

I'm trying to test out Python XML-RPC for the first time, and can't find
anything that executes a call end to end.

I thought that I would use SimpleXMLRPCServer to run a simple server on
localhost, and xmlrpclib to run a client that connects to it, but they don't
seem to register the same functions. The server test code registers 'pow'
and 'add' (in the Python 2.3 distribution) but the client seems to call
"print server.examples.getStateName(41)". It doesn't seem like they were
meant to work together as a unit test, although that would seem logical.

Can anyone help me just get a single XML-RPC call to execute (and I want to
see both the client and server code)? I have googled extensively and
haven't come up with anything.

Also -- I'm investigating this for a nightly build process involving many
machines. There is going to be a master machine that sends requests to 20
other machines to build things. They're just a bunch of Windows XP
machines, with almost no software on them. What software would I need to
install to run XML-RPC servers on them to receive requests? Just Python and
a web server like Apache?

If there are any other _very_ lightweight RPC mechanisms, I would appreciate
hearing about them. I am writing some build scripts in Python, and while I
could for example schedule a task on 20 machines separately, it would be
nicer to have a master machine control when the build happened, etc. and be
able to manage dependencies by waiting for a return result, etc. All I want
to do is execute a python function on a remote machine and get a result
back. It is all done in a local, secure environment.

Thanks for all the previous responses to my questions -- this newsgroup has
been very helpful.

MB
 
M

Moosebumps

OK, I tried the obvious and it worked. : ) I just changed the call to
server.pow(3,5) and it returns the correct result. I wonder why they aren't
set up that way in the first place.

But the second question still stands. I am running both the client and
server on my own machine now (Windows 2000). Would I just need Python and
web server if they were different machines? I would like to avoid
installing a bunch of software on the 20 machines if possible.

thanks,
MB
 
S

Skip Montanaro

MB> OK, I tried the obvious and it worked. : ) I just changed the call
MB> to server.pow(3,5) and it returns the correct result. I wonder why
MB> they aren't set up that way in the first place.

The xmlrpclib module predates SimpleXMLRPCServer by a fair amount. The
getStateName() test was meant to connect to UserLand's original test server.
As I recall, that was the sole function it exported. I don't see any reason
why SimpleXMLRPCServer needs to implement getStateName(), but I imagine it
would be reasonable for xmlrpclib's test to call pow().

MB> But the second question still stands. I am running both the client
MB> and server on my own machine now (Windows 2000). Would I just need
MB> Python and web server if they were different machines? I would like
MB> to avoid installing a bunch of software on the 20 machines if
MB> possible.

You should be able to build a server and a client with just the standard
Python distribution. If performance is an issue (it will be if you are
passing large chunks of data back and forth), there are some things you can
do to speed it up:

* Install Fredrik Lundh's sgmlop module.

* Marshal or pickle your data first, then base64 encode them before
passing them to or fro. This greatly reduces the number of XML tags
on-the-wire, and thus the encode/decode time and data size.
Obviously, this only works if you are talking Python-to-Python.

* Tweak things to gzip-encode the traffic between server and client.

* Use the xmlrpclib.MultiCall class to bundle logical multiple calls
into a single physical XML-RPC call.

Skip
 
M

Moosebumps

MB> But the second question still stands. I am running both the
client
MB> and server on my own machine now (Windows 2000). Would I just need
MB> Python and web server if they were different machines? I would like
MB> to avoid installing a bunch of software on the 20 machines if
MB> possible.

You should be able to build a server and a client with just the standard
Python distribution.

Really? That would be awesome. But I don't see how that works... what do
you enter for the URL? (right now it is just http://localhost, but
obviously I would need to specify 20 different machines for my system. They
are just bare Windows XP Pro machines with a default installation. They're
"Windows Server" machines, I don't think.

If performance is an issue (it will be if you are
passing large chunks of data back and forth), there are some things you can
do to speed it up:

* Install Fredrik Lundh's sgmlop module.

* Marshal or pickle your data first, then base64 encode them before
passing them to or fro. This greatly reduces the number of XML tags
on-the-wire, and thus the encode/decode time and data size.
Obviously, this only works if you are talking Python-to-Python.

* Tweak things to gzip-encode the traffic between server and client.

* Use the xmlrpclib.MultiCall class to bundle logical multiple calls
into a single physical XML-RPC call.

Thanks for these suggestions.

MB
 
S

Skip Montanaro

MB> Really? That would be awesome. But I don't see how that
MB> works... what do you enter for the URL? (right now it is just
MB> http://localhost, but obviously I would need to specify 20 different
MB> machines for my system. They are just bare Windows XP Pro machines
MB> with a default installation. They're "Windows Server" machines, I
MB> don't think.

Doesn't matter. Suppose you ran the server on win.foobar.tv, listening to
port 1234. In the client you'd call ServerProxy like so:

server = ServerProxy("http://win.foobar.tv:1234")
print server.exanples.echo("My dog has fleas")

Skip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top