title: How can I send a message from a flask route to a socket using flask-socketio
body: <p>I have the following scenario I would like to implement:</p>
  
  <ul>
  <li>User surfs to our website</li>
  <li>User enters a bitcoin address.</li>
  <li>A websocket is created to the server, passing the address.</li>
  <li>The server registers a <a href="https://www.blocktrail.com/api/docs#webhooks_init" rel="noreferrer">callback with Blocktrail</a></li>
  <li>When the callback is triggered (a payment was seen by Blocktrail) we send a message back to the browser. </li>
  <li>The page the user is browsing is updated to show the message recieved</li>
  </ul>
  
  <p>I'm using <a href="https://www.blocktrail.com/api/docs#webhooks_init" rel="noreferrer">webhooks from the Blocktrail API</a> to "listen" to an event, being the reception of coins on an address. </p>
  
  <p>Now, when the event happens, the API does a POST to my URL. This should send a message to the browser that is connected to my server with socket.io (such as 'payment seen on blockchain')</p>
  
  <p>So the question is,</p>
  
  <p>How can I send a message from a route to a socket using flask-socketio</p>
  
  <p>Pseudo code:</p>
  
  <pre><code>@app.route('/callback/&lt;address&gt;')
  def callback(id):
      socketio.send('payment seen on blockchain')
  
  @socketio.on('address',address)
  def socketlisten(address):
      registerCallback(address)
  </code></pre>