-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
32 lines (25 loc) · 975 Bytes
/
server.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
29
30
31
32
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
app = Flask(__name__)
socketio = SocketIO(app, async_mode='eventlet')
current_rate = "Initial Current Rate"
next_rate = "Initial Next Rate"
@app.route('/')
def index():
return render_template('index.html', current_rate=current_rate, next_rate=next_rate)
# Modify the 'update_rates' event to 'update' in server.py
@socketio.on('update_rates')
def handle_update_rates(data):
global current_rate, next_rate
current_rate = data['current_rate']
next_rate = data['next_rate']
emit('update', {'current_rate': current_rate, 'next_rate': next_rate}, broadcast=True)
print('Emitted update event:', {'current_rate': 99, 'next_rate': 88})
if __name__ == '__main__':
socketio.run(app, debug=True, host='0.0.0.0')
@socketio.on('connect')
def handle_connect():
print('Client connected')
@sio.on('disconnect')
def on_disconnect():
print('Disconnected from server')