Good day, everyone:<br><br>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 each.<br><br>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.<br>
<br>Do the "conch" protocols not support a factory? Is there an alternative that provides a Telnet client with a lineReceived method?<br><br>What am I doing wrong? :-) I suppose I could pass arguments to ClusterClient by overriding __init__, but that seems inelegant.<br>
<br>Thanks for your help.<br><br>Mark<br><br>----------<br><br>from twisted.internet.protocol import Protocol, ReconnectingClientFactory<br>from sys import stdout<br><br>from twisted.internet import reactor<br><br>from twisted.conch.telnet import StatefulTelnetProtocol<br>
<br>class ClusterClient(StatefulTelnetProtocol):<br><br> def lineReceived(self, data):<br> print self.factory.prompt, self.factory.call<br> print data<br><br>class ClusterClientFactory(ReconnectingClientFactory):<br>
<br> protocol = ClusterClient<br><br> def __init__(self):<br> self.prompt = "call:"<br> self.call = "kd4d"<br><br> def startedConnecting(self, connector):<br> print 'Started to connect.'<br>
<br> def buildProtocol(self, addr):<br> print 'Connected.'<br> self.resetDelay()<br> return ClusterClient()<br><br> def clientConnectionLost(self, connector, reason):<br> print 'Lost connection. Reason:', reason<br>
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)<br><br> def clientConnectionFailed(self, connector, reason):<br> print 'Connection failed. Reason:', reason<br> ReconnectingClientFactory.clientConnectionFailed(self, connector,<br>
reason)<br>if __name__ == '__main__':<br> factory = ClusterClientFactory()<br> factory.maxDelay = 120 # two minutes<br> print factory.prompt, factory.call<br>
reactor.connectTCP("localhost", 8023, factory)<br><br><br> reactor.run()<br><br>-----------------<br><br> File "ClusterClient.py", line 11, in lineReceived<br> print self.factory.prompt, self.factory.call<br>
exceptions.AttributeError: ClusterClient instance has no attribute 'factory'<br>Lost connection. Reason: [Failure instance: Traceback (failure with no frames):<br> <type 'exceptions.AttributeError'>: ClusterClient instance has no attribute 'fa<br>
ctory'<br>]<br><br>