[Twisted-Python] Application mode: Killing a peer connection from the server in a thread. Is this correct?
jon at gina.alaska.edu
Sun Mar 14 01:24:35 EST 2010
I am running a server in application context via:
# code: server.tac
factory = Factory()
factory.protocol = MyProtocol
application = service.Application("MyServer")
service = internet.TCPServer(5555, factory)
# end code
$ twistd -ny server.tac
Here is some of my Protocol code:
# code: myprotocol.py
now = time.time()
if now - transport.activityFlag > 30.0:
self.transport.activityFlag = time.time()
# ... the rest of the methods... not important for this question
# end code
Now here's my problem: I want to kill connections from the server that have
been idle for, say, 30 seconds. An idle connection is one in which is a
_valid_ connection (i.e., it hasn't disconnected from the server) but hasn't
sent any data for 30 seconds. The way I have initially set it up was in a
thread. I simply check the last time it had activity from that particular
transport. The really real problem I am having is when the connection is
closed, the client doesn't know about it. It is simply closed on the server
and the client is left hanging. If I test this in telnet with:
$ telnet localhost 5555
telnet never quits with a message: Connection closed by foreign host. (which
is indeed exactly what I want)
The only way I get this response is if I try to send data to the server
while the connection has been "lost".
Can anyone direct me on the proper way to kill a connection from the server
end in a clean manner?
(By the way, I'm very new to twisted, not so new to Python).
Thanks for any help!
Geographic Information Network of Alaska (GINA)
University of Alaska Fairbanks
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python