[Twisted-Python] PB - Dual Use Objects?
Christopher Armstrong
radix at twistedmatrix.com
Fri Jul 16 12:45:32 EDT 2004
Sergio Trejo wrote:
> 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.
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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040716/e01c0e1f/attachment.pgp
More information about the Twisted-Python
mailing list