XMLRPC Solution Code

dylpkls91 dpickles at pacbell.net
Mon Jul 17 16:46:06 EDT 2006


costello.bob at gmail.com wrote:
> Mind posting it for us lesser beings? ;)

Not at all. I have yet to test it on networked computers, but it works
fine when I run both scripts on my machine.

The hard part now is getting the server code to run as a Windows
service- argh!!!
I can get it installed and started using modified code from:
http://www.schooltool.org/products/schooltool-calendar/documentation/how-to/running-as-a-windows-service/schooltool-service.py/view

but for some reason when the server is a service the client refuses to
connect properly!
Grrr... anybody know why?

Here is the code for the server, the machine that will execute the
commands:

import SimpleXMLRPCServer, os
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.register_function(lambda command: os.popen4(command)[1].read(),
"execute")
server.serve_forever()

And here's the code for the client, the computer that will tell the
server what command to execute:

import xmlrpclib
server = xmlrpclib.Server("http://" + raw_input("Enter the IP address
of the server: ") + ":8000")
output = server.execute(raw_input("Enter a command for the server to
execute: "))
print output




More information about the Python-list mailing list