簡體   English   中英

Python:服務器如何在客戶端了解網絡故障?

[英]Python : How do server come to know of network failure at the client side?

我正在使用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()

謝謝

您必須(1)使用讀取超時和(2)確保在讀取或寫入套接字時對所有錯誤條件做出適當的反應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM