[英]Python : How do server come to know of network failure at the client side?
I am developing a chat based application in Python using twisted
module. 我正在使用twisted
模块在Python中开发基于聊天的应用程序。 After a period of establishing the connection, let us assume, that the network connection fails at the client side. 在建立连接一段时间后,让我们假设网络连接在客户端失败。
How do I make sure that the server is notified about the network failure ? 如何确保服务器收到有关网络故障的通知?
Here is the code snippet( Server program) : 这是代码片段(服务器程序):
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()
Thanks 谢谢
This http://twistedmatrix.com/documents/13.0.0/api/twisted.internet.interfaces.IProtocol.html#connectionLost 这http://twistedmatrix.com/documents/13.0.0/api/twisted.internet.interfaces.IProtocol.html#connectionLost
But to be realy sure, you'd have to implement PING/PONG in the application. 但要确定,您必须在应用程序中实现PING / PONG。 See http://tools.ietf.org/html/rfc2812#section-3.7.2 见http://tools.ietf.org/html/rfc2812#section-3.7.2
您必须(1)使用读取超时和(2)确保在读取或写入套接字时对所有错误条件做出适当的反应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.