question: howto transfer objects between server and client?

O

OpenPavilion

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
 
O

OpenPavilion

Take a look at Pyro; http://pyro.sourceforge.net

--Irmen

Thanks Irmen,

just found out, that if I use "pickle.dumps(object)" (on client side)
and "pickle.loads(object)" (on server side) before and after sending,
I have access to the object.

I love this python language !
Python is a really, really nice language and I often find that the
solution is easier as I thought in the first place ...

Thanks anyway !!
Regards
Bernd
 
L

Lawrence D'Oliveiro

just found out, that if I use "pickle.dumps(object)" (on client side)
and "pickle.loads(object)" (on server side) before and after sending,
I have access to the object.

That's assuming that the client and server can trust each other. If you
can't be sure of that, then this sounds like it could be a security hole.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top