python - How to connect to Flask-WebSocket server? -


i following tutorial try , use flask-websockets in app.

http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent

my problem don't know how connect server.

when make calls flask app, in form:

http://localhost:80/myapp/<route_goes_here>

my app structured follows:

couponmonk/venv/couponmonk     __init__.py     views.py     templates/         index.html 

__init__.py

from flask import flask flask.ext.sqlalchemy import sqlalchemy sqlalchemy.orm import sessionmaker sqlalchemy import * 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 

views.py

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') 

given setup, should put line:

if __name__ == '__main__':     socketio.run(app) 

i'm not sure address put following line in index.html:

index.html

the code in file identical (https://github.com/miguelgrinberg/flask-socketio/blob/master/example/templates/index.html)

var socket = io.connect('what put here?'); 

i've tried http://localhost:80/test , no response. i'm not sure if namespace should part of address or not.

thanks help.

var socket = io.connect('what put here?'); 

is javascript, that'll need go <script> tag somewhere, head.

in tutorial, scroll a socketio client - section starts talking client side of websocket: javascript.

we can @ example's code on github see that section. finally, documentation has html in second code section.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -