我正在使用 twisted
模块在 Python 中开发基于聊天的应用程序。
在建立连接一段时间后,假设客户端网络连接失败。
如何确保服务器收到有关网络故障的通知?
这是代码片段(服务器程序):
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()
谢谢
最佳答案
但要真正确定,您必须在应用程序中实现 PING/PONG。参见 https://www.rfc-editor.org/rfc/rfc2812#section-3.7.2
关于 python : How do server come to know of network failure at the client side?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16852102/