扭曲不检测客户端断开连接

时间:2010-11-18 18:23:30

标签: python networking network-programming twisted

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

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

奇怪的是网络没有连接的东西可以通过吗? Twisted bug?

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

2 个答案:

答案 0 :(得分:5)

这是Twisted FAQ,即使它与Twisted没有任何关系。

答案 1 :(得分: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
相关问题