小编Eng*_*ost的帖子

龙卷风Web和持久连接

如何在TornadoWeb中编写支持持久连接的Http服务器.

我的意思是将能够接收许多请求并在不关闭连接的情况下回答它们.它如何在异步中实际工作?

我只是想知道如何编写处理程序来处理持久连接.它究竟会如何运作?

我有这样的处理程序:

class MainHandler(RequestHandler):

count = 0
@asynchronous
def post(self):

    #get header content type 
    content_type = self.request.headers.get('Content-Type')
    if not content_type in ACCEPTED_CONTENT:
        raise HTTPError(403, 'Incorrect content type')
    text = self.request.body
    self.count += 1     

    command = CommandObject(text, self.count, callback = self.async_callback(self.on_response))
    command.execute()

def on_response(self, response):
    if response.error: raise HTTPError(500)
    body = response.body   
    self.write(body)
    self.flush()
Run Code Online (Sandbox Code Playgroud)

完成后执行调用回调.

是我的正确的权利,事情那样post会多次调用,一个连接数将增加每个来自客户端的httprequest?但对于每个连接,我将有单独的计数值?

asynchronous tornado persistent-connection

4
推荐指数
1
解决办法
2341
查看次数