title: Sending messages actively from Tornado WebSocket server
body: <p>I have a Python WebSocket server. This can return a response when it receives a message.</p>
  
  <pre class="lang-py prettyprint-override"><code>import tornado.web
  import tornado.websocket
  import tornado.ioloop
  
  class WebSocketHandler(tornado.websocket.WebSocketHandler):
  
      def open(self):
          print("New client connected")
          self.write_message("You are connected")
  
      def on_message(self, message):
          self.write_message(u"You said: " + message)
  
      def on_close(self):
          print("Client disconnected")
  
      def check_origin(self, origin):
          return True
  
  application = tornado.web.Application([
          (r"/", WebSocketHandler),
  ])
  
  
  if __name__ == "__main__":
      application.listen(8888)
      tornado.ioloop.IOLoop.instance().start()
  </code></pre>
  
  <p>However, this can't send messages before it receives one. How do I send a message actively? For example, it measures time and if it didn't receive messages for 10 sec, it send "Are you sleeping?".</p>
  
  <p>I want to make chatbot using WebSocket. I use tornado and websocket because I only know this, and I would be interested if you know of better methods to use in this regard.</p>