views:

40

answers:

1

I'm writing my first network application. It manipulates jabber client and comunicates with some service with IQ-stanzas. But details are not important.

This interaction works through twisted xmlstream (python language). Typical situations are described here: http://juick.com/help/api/xmpp/ To be short, I can send a "query" and server relies me with "result".

I implemented some basic actions like "send message", "do action on message recieved". The problem is in operating with stream. Is it better to use deferreds to request any data from server? And how to return the result to the place where it is needed?

You can look through my code here: http://bitbucket.org/boh/tmp/src/56c131cd1e62/juick_app/twisted_app.py I tried to make it minimalistic.

A: 

To pair a response with a reply, you use the iq.id attribute. You can store a few deferreds in a cache indexed by id and run them when they get a reply. Since XMPP is TCP-based, you will mostly get replies in the right order anyway. You can cap the cache and run the deferred's errback if the deferred has been in the cache for a while.

Tobu
What order you get the responses in has nothing to do with the TCP stream; that just guarantees you get them in the order they got to the server's output queue, but a threaded server might have processed them in any order.
Andrew McGregor
Hence my “mostly” and the associative cache.
Tobu