Skip to content Skip to sidebar Skip to footer

Python: Is It Possible To Set The Clientport With Xmlrpclib?

Is it possible to set the clientport for the xmlrpc-connection? I want to say: Client should make a ServerProxy-object to over a specific client port or pseudocode something li

Solution 1:

Try to define a custom transport. This should be something like that:

import xmlrpclib, httplib

classsourcedTransport(xmlrpclib.Transport):defsetSource(self, src):
        self.src = src
    defmake_connection(self, host):
        h = httplib.HTTPConnection(host, source_address= self.src)
        return h

srcPort = 43040
srcAddress = ('', srcPort)
p = sourcedTransport()
p.setSource(srcAddress)
server = xmlrpclib.ServerProxy("server:port", transport=p)

EDIT: bug fix httplib.HTTP => httplib.HTTPConnection

And checked that it works, in python 2.7 (but not before)

Solution 2:

There is no option for this in module xmlrpclib, but you can create your own by modifying the original version. Assuming you use Linux, fetch /usr/lib/python2.7/xmlrpclib.py. Modify the method make_connection accordingly.

Providing a parameter source_address to HTTPConnection is supported by httplib not before Python version 2.7.

Have fun!

Post a Comment for "Python: Is It Possible To Set The Clientport With Xmlrpclib?"