1

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()

ありがとう

4

2 に答える 2

4

このhttp://twistedmatrix.com/documents/13.0.0/api/twisted.internet.interfaces.IProtocol.html#connectionLost

しかし、確実にするには、アプリケーションに PING/PONG を実装する必要があります。https://www.rfc-editor.org/rfc/rfc2812#section-3.7.2を参照してください。

于 2013-05-31T11:03:19.820 に答える
0

(1) 読み取りタイムアウトを使用し、(2) ソケットからの読み取りまたは書き込み時にすべてのエラー条件に適切に対応する必要があります。

于 2013-05-31T11:16:37.663 に答える