【问题标题】:Python : How do server come to know of network failure at the client side?Python:服务器如何知道客户端的网络故障?
【发布时间】:2013-05-31 07:34:37
【问题描述】:

我正在使用twisted 模块在 Python 中开发一个基于聊天的应用程序。 建立连接一段时间后,假设客户端的网络连接失败。

如何确保服务器收到有关网络故障的通知?

这里是sn-p(服务器程序)的代码:

def main():
    """This runs the protocol on port 8000"""



    factory = protocol.ServerFactory()
    factory.protocol = Echo
    PortNo = 8000
    reactor.listenTCP(PortNo,factory)

    reactor.run()

# this only runs if the module was *not* imported
if __name__ == '__main__':
    main()

谢谢

【问题讨论】:

    标签: python networking network-programming twisted


    【解决方案1】:

    【讨论】:

    • 当网络关闭时connectionLost() 事件不会被调用。乒乓球是我现在正在考虑的一个想法。我不确定如何处理来自服务器端所有客户端的 ACK
    【解决方案2】:

    您必须 (1) 使用读取超时 (2) 确保在读取或写入套接字时对所有错误情况做出适当的反应。

    【讨论】:

    • 我还没有成功。感谢您的帮助。
    • 没有成功做什么?不是有用的评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多