I do not see a way in which you can achieve this from endpoints using the API. However, look at the source twisted.internet.endpoints._WrappingProtocol- you could configure the endpoint to use _WrappingFactory*, which causes a delayed callback when the connection is made. At this point, the transport is installed in the protocol, and you can call setTcpKeepAlive.
, , , . .
self.transport.setTcpKeepAlive connectionMade , ( , ).
from twisted.internet import protocol
from twisted.internet import reactor
class EchoProtocol(protocol.Protocol):
def connectionMade(self):
print "Client Connected Detected!"
try:
self.transport.setTcpKeepAlive(1)
except AttributeError: pass
def connectionLost(self, reason):
print "Client Connection Lost!"
def dataReceived(self, data):
self.transport.write(data)
factory = protocol.Factory()
factory.protocol = EchoProtocol
reactor.listenTCP(8000, factory)
reactor.run()
, , , , , .
* , _WrappingFactory ClientFactory .