in my simple client I need a mechanism for reconnecting to the server:
1. If the server is not responding at the momment, the client should keep trying to connect
2. If the connection once become active and the server is restarted, the client should reconnect
3. If the connection is active and no data can be transmited / received for X seconds (link down, router down),
the client should try to reconnect as in the case (1.) (as if the client has never been connected)
It should react in less then 10 seconds.
Unfortunately I can not detect the situation (3.). If I unplug the ethernet while connected, none of my methods is called (ever).
I couldn't find anything like this in the documentation or in the examples.
Here is my testfile:
from twisted.internet.protocol import Protocol, ReconnectingClientFactory
from twisted.internet import reactor
def dataReceived(self, data):
def connectionLost(self, reason):
print 'connection lost', reason
print 'connection made'
def ping(self, *args):
maxDelay = 3
def startedConnecting(self, connector):
print 'started to connect'
def buildProtocol(self, addr):
def clientConnectionLost(self, connector, reason):
print 'lost connection', reason
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
print 'connection failed', reason
ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
reactor.connectTCP('10.10.2.77', 23, EchoClientFactory())