473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

xmlrpc server on red hat 9 question

After figuring out the other day (thanks to everyone here who helped)
how to get the dir lists I want on my unix machine I want to turn the
same thing into an XML-RPC service. Using Simple XMLRPCServer.py I
created my own version by adding my getdirs function and then I call the
code to open the server:

import os
import os.path
import SimpleXMLRPCServer
import xmlrpclib
import SocketServer
import BaseHTTPServer
import sys
class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTP RequestHandler):
def do_POST(self):
"""Handles the HTTP POST request.

Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the _dispatch method for handling.
"""

try:
# get arguments
data = self.rfile.read(int(self.headers["content-length"]))
params, method = xmlrpclib.loads(data)

# generate response
try:
response = self._dispatch(method, params)
# wrap response in a singleton tuple
response = (response,)
except:
# report exception back to server
response = xmlrpclib.dumps(
xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type,
sys.exc_value))
)
else:
response = xmlrpclib.dumps(response, methodresponse=1)
except:
# internal error, report as HTTP server error
self.send_response(500)
self.end_headers()
else:
# got a valid XML RPC response
self.send_response(200)
self.send_header("Content-type", "text/xml")
self.send_header("Content-length", str(len(response)))
self.end_headers()
self.wfile.write(response)

# shut down the connection
self.wfile.flush()
self.connection.shutdown(1)

def _dispatch(self, method, params):
func = None
try:
# check to see if a matching function has been registered
func = self.server.funcs[method]
except KeyError:
if self.server.instance is not None:
# check for a _dispatch method
if hasattr(self.server.instance, '_dispatch'):
return self.server.instance._dispatch(method, params)
else:
# call instance method directly
try:
func = _resolve_dotted_attribute(
self.server.instance,
method
)
except AttributeError:
pass

if func is not None:
return apply(func, params)
else:
raise Exception('method "%s" is not supported' % method)

def log_request(self, code='-', size='-'):
"""Selectively log an accepted request."""

if self.server.logRequests:
BaseHTTPServer.BaseHTTPRequestHandler.log_request( self,
code, size)
def _resolve_dotted_attribute(obj, attr):
"""Resolves a dotted attribute name to an object. Raises
an AttributeError if any attribute in the chain starts with a '_'.
"""
for i in attr.split('.'):
if i.startswith('_'):
raise AttributeError(
'attempt to access private attribute "%s"' % i
)
else:
obj = getattr(obj,i)
return obj
class SimpleXMLRPCServer(SocketServer.TCPServer):

def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
logRequests=1):
self.funcs = {}
self.logRequests = logRequests
self.instance = None
SocketServer.TCPServer.__init__(self, addr, requestHandler)

def register_instance(self, instance):

self.instance = instance

def register_function(self, function, name = None):

if name is None:
name = function.__name__
self.funcs[name] = function
def getdirs(path):
dirs=[]

for entry in os.listdir(path):
entry=os.path.join(path,entry)
if os.path.isdir(entry):
dirs.append(entry)
return dirs
server = SimpleXMLRPCServer(("localhost", 8080))
server.register_function(getdirs)
server.serve_forever()

Now...this seems to run just fine on my red hat 9 machine. Problem is I
cant connect to it from another machine using the following code:

import xmlrpclib

client = xmlrpclib.Server("http://luna:8080")
print client.getdirs('/');

I get a connection refused error. Interestingly enough this works just
dandy if run on the same box as the server piece. Anyone have any
ideas what i need to do to get this to work? I run the java servlet
runner Resin on the box and that always seems to work just fine on the
same port.

thanks,

Jason

Jul 18 '05 #1
0 1888

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: glin | last post by:
Hi I am trying to integrate the xmlrpc server into a class, does anyone know how to get it working? test.html: <html> <head> <title>XMLRPC Test</title> <script src="jsolait/init.js"></script>...
0
by: Juan Carlos CORUÑA | last post by:
Hello all, I'm trying to create a COM Server with an embedded xmlrpc server. Here is way it must work: - The client application (programmed with a COM capable language) instantiates my COM...
1
by: Joxean Koret | last post by:
Hi to all! I'm having troubles to make my XMLRPC application working with non ASCII characters. Example: 1.- In one terminal run the following script: -----------XMLRPC...
1
by: emielvl | last post by:
Hello, I'm developing a client/server architecture based on the XML-RPC implementation in php4. All works pretty well, except that in the response from the server there is no "Content-Length" in...
3
by: David Hirschfield | last post by:
An xmlrpc client/server app I'm writing used to be super-simple, but now threading has gotten into the mix. On the server side, threads are used to process requests from a queue as they come in....
1
by: fortepianissimo | last post by:
I have a simple xmlrpc server/client written in Python, and the client throws a list of lists to the server and gets back a list of lists. This runs without a problem. I then wrote a simple Java...
1
by: tmugavero | last post by:
Hello All, I have a question that has been giving me a bit of trouble. Has anyone been able to connect to C# from non .net C++ via XmlRpc? I have been using the CookComputing XmlRpc Library...
1
by: tmugavero | last post by:
Hello All, I have a question that has been giving me a bit of trouble. Has anyone been able to connect to C# from non .net C++ via XmlRpc? I have been using the CookComputing XmlRpc Library...
6
by: half.italian | last post by:
Hi, I'm trying to serve up a simple XMLRPC server as a windows service. I got it to run properly, I'm just not sure how to stop it properly. Most of the documentation/examples I found for this...
4
by: care02 | last post by:
I have implemented a simple Python XMLRPC server and need to call it from a C/C++ client. What is the simplest way to do this? I need to pass numerical arrays from C/C++ to Python. Yours, Carl
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.