【问题标题】:twisted not detecting client disconnects扭曲未检测到客户端断开连接
【发布时间】:2010-11-18 18:23:30
【问题描述】:

有人有这方面的经验吗?我有一个扭曲的应用程序。客户端连接到服务器。我添加了一个功能,如果客户端连接到服务器,但已经有来自该 IP 地址的客户端在运行,它会断开新客户端的连接。

有时,我会关闭客户端计算机(准确地说是虚拟机),而无需手动关闭 Python 程序。当我这样做时,偶尔但经常,服务器不会检测到任何断开连接。当计算机恢复并尝试重新连接时,服务器坚持认为已经存在来自该 IP 的连接。到目前为止我找到的唯一解决方案是重新启动服务器。

没有断开连接会是奇怪的联网事情吗?扭曲的错误?

我 99% 确定这不是我的代码处理断开连接的错误。我的代码设置为每当连接丢失时调用connectionLost,包括关闭机器的大多数情况,它要么记录一个字符串,说明断开连接的情况,要么在发生奇怪的事情时抛出异常。这些东西都没有出现在日志中。

【问题讨论】:

  • Twisted 框架在所有概念级别定义了事件和 eventHandler - 传输/连接、协议等来处理断开连接。所以检查代码会有所帮助。您可以发布表现出该行为的简化版本的代码。
  • @pyfunc:我会挖掘代码。我现在怀疑网络问题,因为我让客户端不断尝试重新连接,并且在某些情况下它最终能够连接(尽管在其他情况下不是)。

标签: python networking network-programming twisted


【解决方案1】:

这是一个Twisted FAQ,尽管它与 Twisted 没有任何关系。

【讨论】:

    【解决方案2】:

    嘿,我真不敢相信我忘记了我在网络课上学到的所有东西......

    (2:09:44 PM) coworker: this is the expected behaviour
    (2:10:15 PM) coworker: the server has no way to know if someone dies, or is just quiet
    (2:10:35 PM) coworker: unless ofcourse the server has some kind of ping/keepalive message
    (2:15:38 PM) claudiu: ah so if they have no communicatin
    (2:15:42 PM) claudiu: there's no way to tell that a TCP connection has died
    (2:15:47 PM) claudiu: i remember learning that now, yes..
    (2:16:23 PM) claudiu: but if i just make the server ping the client then it'll figure out soon enough from lack of ACKs that it's dead, right?
    (2:16:45 PM) coworker: right
    

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 2011-07-08
      • 1970-01-01
      • 2020-01-15
      • 1970-01-01
      • 2012-05-17
      • 2021-02-21
      • 2020-08-27
      • 2013-04-17
      相关资源
      最近更新 更多