[Twisted-Python] AMP with a long-lived connection - results and deferred?

Oon-Ee Ng ngoonee.talk at gmail.com
Wed Oct 28 00:33:58 MDT 2015


One 'answer' that I've gotten so far is in this link -
http://stackoverflow.com/questions/15640393/how-to-create-bi-directional-messaging-using-amp-in-twisted-python
- but that doesn't seem to achieve what I want, at least not in the
way I want it. It does a callRemote from the server in the function
called by the client (using callRemote). As I understand things,
that's what deferred is meant to solve, and anyway this seems to
invalidate the reason for using amp.Command inheritence anyway (as the
response is required).

To be clear, that way does 'work', but it doesn't seem to be doing the
sort of bidirectional messaging AMP should be doing.

In summary:- how do I see the response from client side without making
a new connection every time I have something to send (as done in the
ampclient.py example)?

On Wed, Oct 28, 2015 at 2:24 PM, Oon-Ee Ng <ngoonee.talk at gmail.com> wrote:
> Working off the example ampserver.py and ampclient.py examples, I
> wanted to build a client which maintains a single connection while
> allowing the passing of messages back and forth. However I'm stuck at
> one of the most basic steps, getting back the result (without
> 'completing' the connection).
>
> The ampclient.py example simply connects, does a callRemote on the
> resulting protocol, and adds callbacks to extract the result from a
> dictionary and print it. The deferred being used in this case is
> produced by connectProtocol.
>
> I'm trying to write a client (inheriting from amp.AMP) which is
> embedded in a kivy GUI, something which is quite possible using the
> _threadedselect reactor.
>
> On connection, I use the connectionMade method to save the 'self' (in
> this case, the client inheriting from amp.AMP) in my kivy app. I can
> then call a function which does a callRemote on this saved client,
> which indeed triggers the server appropriately.
>
> The callRemote returns a deferred (from reading docs online, a remote
> reference). I can't figure out what to do with it, specifically in
> terms of getting the result ('total', when calling Sum from
> ampserver.py).
>
> Assistance much appreciated.




More information about the Twisted-Python mailing list