[Twisted-Python] Detect idle in a LineReceiver

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu Jan 17 06:07:52 EST 2008


Matteo Beniamino wrote:
> I'm trying to parse messages coming from some serial ports and TCP/IP
> connections using a protocol derived from a basic.LineReceiver .
> Everything works fine. Now I'd like to detect when a client is not
> sending data for a certain amount of time and add a callback to handle
> this situation, but I don't know how to achieve this. Does anyone know
> if  there is something I can do at Factory or Protocol level? There is
> no problem in changing the LineReceiver approach with something
> different.

You may use the protocol.policies.TimeoutMixin class.
See the code of protocols/ftp.py to see a usage of it.

Your protocol must implement the timeoutConnection() method,
which is called if your code does not call resetTimeout() often enough.
Then, just call it at the beginning of lineReceived!

Amaury Forgeot d'Arc

More information about the Twisted-Python mailing list