[Twisted-Python] Is AMP a bidirectional protocol?
nathan.stocks at gmail.com
Wed Feb 27 16:34:06 EST 2008
On Wed, Feb 27, 2008 at 1:47 PM, Drew Smathers <drew.smathers at gmail.com> wrote:
> On Wed, Feb 27, 2008 at 2:09 PM, Nathan <nathan.stocks at gmail.com> wrote:
> > On Wed, Feb 27, 2008 at 11:50 AM, Drew Smathers <drew.smathers at gmail.com> wrote:
> > > On Wed, Feb 27, 2008 at 12:57 PM, Nathan <nathan.stocks at gmail.com> wrote:
> > > > Is the AMP protocol bidirectional (beyond the response you get to each
> > > > message)?
> > >
> > > Yes:
> > > http://djfroofy.livejournal.com/3509.html
> > Drew, you're everywhere!
> > Ok, so next question:
> > How do you access the callRemote method from outside the protocol
> > itself on the server side? In the example above, from the server's
> > main() could you call pf.protocol.CallRemote()?
> I think looking at David's chat demo will steer you in the right direction:
> In a nutshell - just keep them in list or dict bound to the factory
> and be sure to do cleanup on connectionLost.
Ok, so after much staring at code, it looks the pattern is as follows:
1) Create a custom factory class that subclasses ServerFactory and
adds a dict to store "protocol" objects and sets its own self.protocol
to the custom protocol that subclasses amp.AMP.
2) Somewhere in the custom protocol (He did it in a login function,
but I'm assuming I could do it in connectionMade if I wanted to?),
access the factory's dict through self.factory.whatever and stick
"self" (the current protocol object) in the dict, preferably keyed by
some identifier that lets you pick out the one you want later
(ServerFactory.protocol <=> AMP.factory ... so circular!)
3) Send messages from the server to a specific client with
Did I get that right?
More information about the Twisted-Python