Tornado Web & Persistent Connections

Posted by Engrost on Stack Overflow See other posts from Stack Overflow or by Engrost
Published on 2009-11-26T14:34:08Z Indexed on 2010/04/08 23:33 UTC
Read the original article Hit count: 313

How can I write Http server in TornadoWeb that will support persistent Connections.

I mean will be able to receive many requests and answer to them without closing connection. How does it actually work in async?

I just want to know how to write handler to handle persistent connection. How actually would it work?

I have handler like that:

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

execute calls callback when finishes.

is my asumption right that with things that way post will be called many times and for one connection count will increase with each httprequest from client? but for each connection I will have separate count value?

© Stack Overflow or respective owner

Related posts about tornado

Related posts about persistent-connection