[Twisted-Python] Client Logic

Glyph glyph at twistedmatrix.com
Tue Oct 7 22:58:28 MDT 2014


On Oct 6, 2014, at 5:16 PM, Benjamin Schollnick <bschollnick at gmail.com> wrote:

> Now the client works right now, but I’m concerned that I can’t figure out how to immediately read for a reply packet from the server.

First, if you want to "immediately" do anything, you really need to delete that "time.sleep(.5)" line from your code.  It will block the whole reactor from getting work done :).

> For example, when I send the Set_SiteCode packet, I may receive a reply.  
> 
> But how would that occur in the Twisted framework?

dataReceived will be called with the data when it arrives.  If you're expecting the data that is being sent to be a reply to some message, you should have the code that sends that message return a Deferred; that's what Deferreds are for, representing request/response patterns.

> In my testing the dataReceived function is not being called, so I can’t trap it there, plus I’m not sure how I would figure that logic.

If dataReceived is not getting called, you're not getting data, so no reply has been sent.  You haven't included enough of your program for me to tell why no data is getting sent, though.  Presumably you've got some stuff hooking up your serial port and running the reactor, but without seeing how that works, I can't even guess at what's wrong.

> Can anyone suggest a method to do this?

dataReceived it is :).

> The second question, as far as I can tell, isn’t very solvable.  I’d like to add a “Press Q to quit” type logic to the code.  But I don’t see a way to do this easily in twisted?  (platform unspecific, but it’s running Mac OS X / Unix right now).

Where do you want to press "Q"?  Do you mean you want to pop up a GUI, or wait for the user to type a "Q" in a Terminal window, or do you mean you want the thing on the other end of the serial port to send a "Q"?  Also, what is "UNIX"?

-g
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20141007/e7d0a73f/attachment-0002.html>


More information about the Twisted-Python mailing list