[Twisted-Python] Twisted usage

Glyph Lefkowitz glyph at twistedmatrix.com
Thu Apr 15 02:22:44 EDT 2010

On Apr 14, 2010, at 10:51 AM, vitaly at synapticvision.com wrote:

> hi,
> is there any examples how to create (using Twisted)
> client that creates several TCP requests one after another and handle in
> asynch manner TCP responses for previous requests?
> Thanks.

twisted.protocols.amp and twisted.spread.pb both implement this.

In a nutshell: in connectionMade, initialize a dictionary on your protocol object mapping request IDs to Deferreds.  When you issue a request, make a new Deferred and put it into that dictionary.  When you receive a response, pop the Deferred out of that dictionary by looking up the key present in the response, and call its .callback() method.

Is that what you were looking for?

More information about the Twisted-Python mailing list