<br>Can anybody provide a an example on how I would best send <br>a data structure (i.e. an ElemenTree from elementtree) over from<br>a server to a client process. I followed somewhat the example in<br>the documentation and used the perspective broker &quot;pb&quot; to send
<br>an &quot;simple&quot; structure (some class with simple members)<br><br>When I changed to a more complex class definition, I obviously got<br>an InsecureJelly exception. <br><br>I'm sure this question must have come up a number of times. I'm new
<br>in using twisted and not everything is so obvious at the beginning to me :-(<br><br>Many thanks for the help<br><br>Franz<br><br>Attached is the sample code I used:<br><br>sending test1 --&gt; OK<br>sending test2 --&gt; InsecureJelly exception
<br><br>------&nbsp;&nbsp; pbsimple.py (server) -------<br>from twisted.spread import pb, jelly<br>from twisted.internet import reactor<br><br>class test:<br>&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp; x = 3.<br>&nbsp;&nbsp;&nbsp; y = 4.<br><br>class Bag:<br>&nbsp; def setContent(self,content):
<br>&nbsp;&nbsp;&nbsp; self.content = content<br>&nbsp; def printContent(self):<br>&nbsp;&nbsp;&nbsp; print &quot;My data is&quot;, self.content<br><br>class CopyBag(Bag, pb.Copyable):<br>&nbsp; pass<br><br>class Sender(pb.Root):<br>&nbsp; def __init__(self, bag):<br>
&nbsp;&nbsp;&nbsp; self.bag = bag<br><br>&nbsp; def remote_sendBag(self, remote):<br>&nbsp;&nbsp;&nbsp; self.remote = remote<br>&nbsp;&nbsp;&nbsp; d = remote.callRemote(&quot;takeBag&quot;, self.bag)<br>&nbsp;&nbsp;&nbsp; d.addCallback(self.ok).addErrback(self.notOk)<br><br>&nbsp; def ok(self, response):
<br>&nbsp;&nbsp;&nbsp; print &quot;info: %s&quot; % response<br>&nbsp;&nbsp;&nbsp; d = self.remote.callRemote(&quot;finishTransfer&quot;)<br>&nbsp;&nbsp;&nbsp; d.addErrback(self.notOk)<br>&nbsp;&nbsp;&nbsp; return None<br><br>&nbsp; def notOk(self, failure):<br>&nbsp;&nbsp;&nbsp; if failure.type == jelly.InsecureJelly
:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;error: InsecureJelly&quot;<br>&nbsp;&nbsp;&nbsp; elif failure.type == pb.PBConnectionLost:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;info: data transfer finished&quot;<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; print failure<br>&nbsp;&nbsp;&nbsp; return None<br><br>def main():
<br>&nbsp; from pbsimple import CopyBag<br><br>&nbsp; icae = iCAEconfig()<br>&nbsp; bag = CopyBag()<br><br>&nbsp; bag.setContent('simple data') # --&gt; OK<br>&nbsp; #bag.setContent(test())&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # --&gt; InsecureJelly<br>&nbsp; sender = Sender(bag)<br>
<br>&nbsp; factory = pb.PBServerFactory(sender)<br>&nbsp; reactor.listenTCP(8789, factory)<br>&nbsp; reactor.run()<br><br>if __name__ == '__main__':<br>&nbsp; main()<br><br>-----------------------------<br><br>------------&nbsp; pbsimleclient.py&nbsp; -----------------
<br><br>from twisted.spread import pb<br>from twisted.internet import reactor<br>from twisted.python import util<br><br>from pbsimple import Bag, CopyBag<br><br>class ReceiverBag(Bag,pb.RemoteCopy):<br>&nbsp; pass<br><br>pb.setUnjellyableForClass
(CopyBag, ReceiverBag)<br><br>class Receiver(pb.Referenceable):<br>&nbsp; def remote_takeBag(self, bag):<br>&nbsp;&nbsp;&nbsp; self.bag = bag<br>&nbsp;&nbsp;&nbsp; return &quot;data arrived safe and sound&quot; # positive acknowledgement<br><br>&nbsp; def remote_finishTransfer(self):
<br>&nbsp;&nbsp;&nbsp; print &quot;got bag:&quot;, self.bag<br>&nbsp;&nbsp;&nbsp; reactor.stop()<br><br>&nbsp; def requestBag(self,remote):<br>&nbsp;&nbsp;&nbsp; print &quot;asking server for sending the data bag&quot;<br>&nbsp;&nbsp;&nbsp; remote.callRemote(&quot;sendBag&quot;,self)<br>
<br>def getContentFromServer():<br><br>&nbsp; receiver = Receiver()<br>&nbsp; factory = pb.PBClientFactory()<br>&nbsp; reactor.connectTCP(&quot;localhost&quot;, 8789, factory,30)<br>&nbsp; d = factory.getRootObject()<br>&nbsp; d.addCallback(receiver.requestBag
)<br>&nbsp; reactor.run()<br>&nbsp; return receiver.bag.content<br><br>if __name__ == '__main__':<br>&nbsp; print getContentFromServer()<br><br>---------------------------------------------------------<br><br>