0
我正在寫一個簡單的網絡服務器應用程序使用扭曲。應用程序將獲得一個字符串並返回它接收的字符串的反向。扭曲的關閉網絡服務器連接
這一切正常。現在我需要關閉套接字連接,如果5分鐘不活動。
這裏是我的服務器代碼: -
from twisted.internet import reactor, protocol
class Echo(protocol.Protocol):
"""This is just about the simplest possible protocol"""
def dataReceived(self, data):
"As soon as any data is received, write it back."
self.transport.write(data[::-1])
def main():
"""This runs the protocol on port 8000"""
factory = protocol.ServerFactory()
factory.protocol = Echo
reactor.listenTCP(8000,factory)
reactor.run()
# this only runs if the module was *not* imported
if __name__ == '__main__':
main()
~
https://stackoverflow.com/q/11911453/892383 – Cyphase