question: howto transfer objects between server and client?

OpenPavilion BerndWill at googlemail.com
Sat Aug 11 05:04:36 EDT 2007


Hello community,

maybe one of you can help me out with a question regarding the
transfer of objects betwen client an server:
I have three files:

####### ClassA.py #######
class ClassA:
    def setA(self, newA):
        self.a = newA
    def getA(self):
        return self.a

####### client.py #######
import xmlrpclib
from ClassA import *
a = ClassA()
a.setA(4711)
server = xmlrpclib.ServerProxy("http://localhost:8888")
print server.getA(a)        # <= here I would like to hand over an
object

####### server.py #######
import SimpleXMLRPCServer
from ClassA import *
class Handler:
	def getA(self, aClass):
		return aClass.getA()   # <- XMLRPC only transports simple types and
dictionaries, but no objects
handler_object = Handler()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(handler_object)
print "Listening on port 8888"
server.serve_forever()


The problem is, that though I hand a ClassA object to the XMLRPC
server, the server only receives a dictionary (only transfering simple
objects is a XMLRPC feature: http://docs.python.org/lib/module-xmlrpclib.html)

Since XMLRPC has limited features:  Is there any other server/client
technique to transfer objects (not strings, or dictionaries, but self
defined object types) ?

Regards
Bernd




More information about the Python-list mailing list