title: Tornado - How to implement long polling client
body: <p>I'm trying to implement long pulling client in Tornado, that interacts with an asynchronous Tornado server.</p>
  
  <p>What happens is one of 2 things:</p>
  
  <ol>
  <li>Either the client timesout, or</li>
  <li>The client receives all the messages at once after finishing the
  whole background process, similar to blocking ones</li>
  </ol>
  
  <p>This is the client I use:</p>
  
  <pre><code>from tornado import ioloop
  from tornado import httpclient
  
  print "\nNon-Blocking AsyncHTTPClient"
  import tornado.ioloop
  
  def async_call(response):
          if response.error:
                  response.rethrow()
          print "AsyncHTTPClient Response"
          ioloop.IOLoop.instance().stop()
  
  http_client = httpclient.AsyncHTTPClient()
  http_client.fetch("http://localhost:9999/text/", async_call)
  ioloop.IOLoop.instance().start()
  </code></pre>
  
  <p>Is this the right way to write a long-polling/comet client?</p>
  
  <p>I would also appreciate for those who will answer to provide a sample async-server in Tornado, because may be I'm writing the cometed Tornado server wrongly... I'm a bit new to the whole long-polling process in general.</p>