扭曲的关闭Web服务器连接

时间:2015-08-20 02:44:18

标签: python twisted

我正在使用twisted编写一个简单的Web服务器应用程序。应用程序将获得一个字符串并返回它收到的字符串的反向。

一切正常。现在,如果不活动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()
~

1 个答案:

答案 0 :(得分:1)

将这些方法添加到您的课程中:

echo "<h3>Email Addresses:</h3>";
$xml =  new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');

foreach ($result as $title) {
  echo $title->attributes()->address . "<br>";
 }
?>
i to used only email to retrive from google contacts how to retrive phone number and other detaisl

这使得在建立连接时,您的协议将在5分钟内安排定时呼叫以关闭连接。如果连接关闭,否则将取消超时。