-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
28 lines (23 loc) · 864 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
# Creating a flask app and using it to instantiate a socket object
app = Flask(__name__)
socketio = SocketIO(app)
# values['slider1'] and values['slider2'] store the current value of the sliders
# This is done to prevent data loss on page reload by client.
values = {
'slider1': 25,
'slider2': 0,
}
# Handler for default flask route
# Using jinja template to render html along with slider value as input
@app.post('/')
def index():
return render_template('index.html',**values)
# Handler for a message recieved over 'connect' channel
@socketio.on('connect')
def test_connect():
emit('after connect', {'data':'Lets dance'})
# Notice how socketio.run takes care of app instantiation as well.
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0:5001')