title: Continuously sending data from Python Flask server to client through Websockets
body: <p>I am setting up a dashboard which requires a Python Flask server to fetch public transport data once every few seconds or so and send this data to a client webpage through websockets. I am using FlaskSocketIO to achieve this. </p>
  
  <p>I am able to send a message upon the <code>'connect'</code> event, for example, but I've been unable to find a way to continuously update this message. This is my approach:</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask, render_template, url_for, request
  from flask_socketio import SocketIO, emit, send
  import eventlet
  eventlet.monkey_patch()
  
  app = Flask(__name__)
  socketio = SocketIO(app, logger=True, engineio_logger=True)
  
  def listen():
      while True:
          message = # some updating message
          emit('message', message)
          socketio.sleep(1)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  @socketio.on('connect')
  def handle_connect():
      listen()
  
  if __name__ == "__main__":
      socketio.run(app, debug=True)
  </code></pre>
  
  <p>The logger says it sends the message. However, on the client side, no message is recieved. The client side JavaScript is:</p>
  
  <pre class="lang-js prettyprint-override"><code>var socket = io();
  
  socket.on('message', function(msg) {
      console.log(msg);
  });
  </code></pre>