[Twisted-Python] LineReceiver Protocol
radeex at gmail.com
Sun Nov 21 02:57:26 EST 2004
On Sat, 20 Nov 2004 23:12:18 -0800, Michael Mata
<michael.mata at gaigen.net> wrote:
> Is there a way to extend the LineReceiver protocol to take action on a
> continued, periodic basis? Currently, the protocol only does work when
> a line is received. However, there are times when the script should
> take action without waiting to receive a line.
It doesn't have anything to do with the protocol; what you want is
http://twistedmatrix.com/documents/current/howto/time has more information.
> Another example might be a global message that needs to be sent to all
> connections. The message would have to be stored in message queue and
> sent only when lineReceived is called. It would be nice if the message
> could instead be sent imediately even if the connection was currently idle.
For this you just want to keep track of all the protocols you want to
send stuff to. doc/examples/chatserver.py shows how to do this.
basically, in your lineReceived, you can do something like "for prot
in self.factory.protocols: prot.sendMessage(line)".
Twisted | Christopher Armstrong: International Man of Twistery
Radix | Release Manager, Twisted Project
More information about the Twisted-Python