pythonsocketsxmlrpclibsimplexmlrpcserver

Python SimpleXMLRPCServer : Socket Error , Connection Refused


I am trying to list the contents of a directory on a server. If the client and server code is executed on the same machine, it works perfectly. However, running the client code from another machine using the IP of the server gives me a Errno 111:Socket Error. Connection Refused

Server Code :

from SimpleXMLRPCServer import SimpleXMLRPCServer
import logging
import os

# Set up logging
logging.basicConfig(level=logging.DEBUG)

server = SimpleXMLRPCServer(('localhost', 9000), logRequests=True)

# Expose a function
def list_contents(dir_name):
    logging.debug('list_contents(%s)', dir_name)
    return os.listdir(dir_name)
server.register_function(list_contents)

try:
    print 'Use Control-C to exit'
    server.serve_forever()
except KeyboardInterrupt:
    print 'Exiting'

Client code :

import xmlrpclib

proxy = xmlrpclib.ServerProxy('http://192.168.239.148:9000')
print proxy.list_contents('/home/thejdeep/rpc_test/fd/')

Solution

  • Try binding the server to 0.0.0.0 rather than localhost...

    server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=True)