[Twisted-Python] Is AMP a bidirectional protocol?

David Ripton dripton at ripton.net
Wed Feb 27 16:40:33 EST 2008


On 2008.02.27 13:46:56 -0700, Nathan wrote:
> On Wed, Feb 27, 2008 at 12:10 PM, David Ripton <dripton at ripton.net> wrote:
> >  It was non-obvious to me too.
> >
> >  You call callRemote on the server-side Protocol to send a message to the
> >  client side.
> >
> >  I have a little demonstration PyGTK / AMP chat program at
> >  http://ripton.net/hg/ampchat/
> 
> I tried to look at your demo chat program, but all I could find was a
> mercurial summary page.  Do I need to install mercurial and check it
> out using that URL?  (I've never used mercurial)

You can do that.  Or you can click around in the links within the
Mercurial web interface until you see the code.  (I think you want
"manifest" and "file".)

> I don't quite understand what you mean by "on the server-side
> Protocol."  I have multiple clients connected to the server
> simultaneously, so if you mean (in the case of
> http://djfroofy.livejournal.com/3509.html ) calling
> TheServer.callRemote, then I don't see how it would know _which_
> client to send the message to.  I'm obviously misunderstanding
> something!

Each time a client connects to the server, a new protocol instance is
created on the server side.  When the client successfully logs in, I
add the username:protocol to a dict in the server-side factory.  So I
know how to find clients by username.

Then if someone sends a private message, I lookup the target username's
protocol in the dict, and do protocol.callRemote(commands.Send, message,
sender)

-- 
David Ripton    dripton at ripton.net




More information about the Twisted-Python mailing list