[Twisted-Python] How to run function from protocol class

Michał Tyde ajchos at wp.pl
Fri Aug 12 07:48:27 EDT 2005

I got the code:
from twisted.internet.protocol import Protocol

class MyClientProtocol(Protocol):
	buffer = ''
	def connectionMade(self):
		self.transport.write('hello world')
	def myFunction(self):
	def dataReceived(self, data):
		self.buffer += data
		if self.buffer == 'hello world':
from twisted.internet.protocol import ClientFactory

class MyFactory(ClientFactory):
	protocol = MyClientProtocol
	def startedConnecting(self, connector):
		pass # we could connector.stopConnecting()
	def clientConnectionLost(self, connector, reason):
		connector.connect() # reconnect
	def clientConnectionFailed(self, connector, reason):
		print "connection failed"

from twisted.internet import reactor, task

#l = task.LoopingCall(t.myFunction)

reactor.connectTCP('localhost', 7771, MyFactory(), timeout=30)

I want to run my function myFunction every 5 sec (commented code). I want to use a task.LoopingCall loop. 
I am run out of new ideas. I don't know how to do this. Help please.

More information about the Twisted-Python mailing list