[Twisted-Python] PB - Dual Use Objects?

I'm curious, for those who use PB for their projects, do they make their objects at each end of the wire dual use (meaning, both objects run a PB Server and PB Client Factory such that each object can remotely call the other), or do most people stick to a typical client-server model wherby the PB Server Factory object just waits for requests from the Client and does not attempt to initiate any messages to the client? I ask because as a newbie to Twisted, I also started reading the twisted.flow HowTo and it looks like there are some really interesting things that could be done with PB. I have an app in mind whereby a PB Client (A) triggers a PB Server, and then the PB Server expects incoming data from another PB Client (B) but the data that comes in from B is useful to pass back to A (all in a deferred manner however). Therefore the PB Server acts as an intermediary. But this could get really hairy if I turned the PB Server into a server handling multiple requests from PB Clients of type A and PB Clients of type B (could look like a spaghetti bowl f the Server is required to route data from the Bs to the As) so maybe better to stick with a typical client-server model. Serg _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus

Sergio Trejo wrote:
No, this is very simple. First of all, you need the Bs to pass a "mind" object to pb.login(). It'll probably be a Referenceable subclass instance. You'll get this mind object passed to your Realm's requestAvatar method, so you can save it wherever relevant there. Let's pretend this object has a messageFromAnA remote method. Then the As connect, and do middleman.callRemote('doSomethingToAB'): def remote_doSomethingToAB(self): return self.mind.callRemote('messageFromAnA') callRemote will return a Deferred that fires with the result from B's messageFromAnA method, and PB will pass this result off as the result to A, so A is getting the result that B returned. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/

Sergio Trejo wrote:
No, this is very simple. First of all, you need the Bs to pass a "mind" object to pb.login(). It'll probably be a Referenceable subclass instance. You'll get this mind object passed to your Realm's requestAvatar method, so you can save it wherever relevant there. Let's pretend this object has a messageFromAnA remote method. Then the As connect, and do middleman.callRemote('doSomethingToAB'): def remote_doSomethingToAB(self): return self.mind.callRemote('messageFromAnA') callRemote will return a Deferred that fires with the result from B's messageFromAnA method, and PB will pass this result off as the result to A, so A is getting the result that B returned. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/
participants (2)
-
Christopher Armstrong
-
Sergio Trejo