title: How to connect to Flask-WebSocket server?
body: <p>I am following this tutorial to try and use <code>Flask-WebSockets</code> in my app.</p>
  
  <p><a href="http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent" rel="nofollow">http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent</a></p>
  
  <p>My problem is that I don't know how to properly connect to the server.</p>
  
  <p>When I make calls to my flask app, they are in the form:</p>
  
  <p><strong><code>http://localhost:80/myapp/&lt;route_goes_here&gt;</code></strong></p>
  
  <p>My app is structured as follows:</p>
  
  <pre><code>couponmonk/venv/couponmonk
      __init__.py
      views.py
      templates/
          index.html
  </code></pre>
  
  <p><strong>__init__.py</strong></p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  from sqlalchemy.orm import sessionmaker
  from sqlalchemy import *
  from flask.ext.socketio import SocketIO, emit       
  
  app = Flask(__name__)    
  socketio = SocketIO(app)                                                                                                                             
  engine =  create_engine('mysql://root:my_password@localhost/my_db_name') 
  DBSession = sessionmaker(bind=engine)
  
  import couponmonk.views
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from couponmonk import app, DBSession, socketio
  
  @socketio.on('my event', namespace='/test')
  def test_message(message):
      emit('my response', {'data': message['data']})
  
  
  @app.route('/', methods = ['GET'])
  def index():
      return render_template('index.html')
  </code></pre>
  
  <p>Given my setup, where should I put this line:</p>
  
  <pre><code>if __name__ == '__main__':
      socketio.run(app)
  </code></pre>
  
  <p>I'm also not sure what address to put for the following line in <code>index.html</code>:</p>
  
  <p><strong>index.html</strong></p>
  
  <p>The code in this file is identical to this (<a href="https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/templates/index.html" rel="nofollow">https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/templates/index.html</a>)</p>
  
  <pre><code>var socket = io.connect('what to put here?');
  </code></pre>
  
  <p>I've tried <code>http://localhost:80/test</code> and get no response. I'm not sure if the <code>namespace</code> should be part of the address or not. </p>
  
  <p>Thanks for your help.</p>