[Twisted-Python] Question about ReconnectingClientFactory and conch StatefulTelnetProtocol

Mark Bailey mebly5343 at gmail.com
Fri Feb 5 19:23:04 EST 2010

Good day, everyone:

Continuing my effort to learn Python and Twisted, I need to create several
Telnet clients and somehow send two arguments to each and receive data from

I tried the same pattern that I used with the Telnet server and created a
Factory, actually a ReconnectingClientFactory.  It doesn't work.  My source
and the error (no attribute 'factory') are below.

Do the "conch" protocols not support a factory?  Is there an alternative
that provides a Telnet client with a lineReceived method?

What am I doing wrong?  :-)  I suppose I could pass arguments to
ClusterClient by overriding __init__, but that seems inelegant.

Thanks for your help.



from twisted.internet.protocol import Protocol, ReconnectingClientFactory
from sys import stdout

from twisted.internet import reactor

from twisted.conch.telnet import StatefulTelnetProtocol

class ClusterClient(StatefulTelnetProtocol):

    def lineReceived(self, data):
        print self.factory.prompt, self.factory.call
        print data

class ClusterClientFactory(ReconnectingClientFactory):

    protocol = ClusterClient

    def __init__(self):
        self.prompt = "call:"
        self.call = "kd4d"

    def startedConnecting(self, connector):
        print 'Started to connect.'

    def buildProtocol(self, addr):
        print 'Connected.'
        return ClusterClient()

    def clientConnectionLost(self, connector, reason):
        print 'Lost connection.  Reason:', reason
        ReconnectingClientFactory.clientConnectionLost(self, connector,

    def clientConnectionFailed(self, connector, reason):
        print 'Connection failed. Reason:', reason
        ReconnectingClientFactory.clientConnectionFailed(self, connector,
if __name__ == '__main__':
    factory = ClusterClientFactory()
    factory.maxDelay = 120  #  two minutes
    print factory.prompt, factory.call
    reactor.connectTCP("localhost", 8023, factory)



  File "ClusterClient.py", line 11, in lineReceived
    print self.factory.prompt, self.factory.call
exceptions.AttributeError: ClusterClient instance has no attribute 'factory'
Lost connection.  Reason: [Failure instance: Traceback (failure with no
 <type 'exceptions.AttributeError'>: ClusterClient instance has no attribute
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100205/a725d2ac/attachment.htm 

More information about the Twisted-Python mailing list