Close inactive connections in Twisted

前端 未结 1 1145
情书的邮戳
情书的邮戳 2021-01-23 16:36

I\'m running a Twisted server with the LineReceiver protocol. Sometimes clients will disconnect silently, so Twisted keeps the connection open. And because the server doesn\'t

相关标签:
1条回答
  • 2021-01-23 17:19

    You can schedule timed events using reactor.callLater. Based on this, there's a helper for adding timeouts to protocols, twisted.protocols.policies.TimeoutMixin.

    Another approach is to use TCP keep-alives, which you can enable using the transport's setTcpKeepAlive method.

    And another approach is to use application-level keep-alives. Essentially send a ''noop'' once in a while. It doesn't need a response. If the connection has been lost, the extra data in the send buffer will cause the TCP stack to eventually notice.

    See also the FAQ entry.

    0 讨论(0)
提交回复
热议问题