2013-05-31 163 views
1

我正在使用twisted模块开发基于聊天的Python应用程序。 建立连接一段时间后,让我们假设,客户端的网络连接失败。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() 

感谢

回答

0

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

+0

虽然我还没有成功。谢谢你的帮助。 – Kiran

+0

还没有成功做什么?没有用的评论。 – EJP

相关问题