-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (21 loc) · 732 Bytes
/
app.py
File metadata and controls
25 lines (21 loc) · 732 Bytes
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
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key' #can ignore for now, should be setup in the future though
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
# WebSocket event handlers
@socketio.on('send_json')
def handle_json(data):
print(f'Received JSON: {data}')
# Modify the received data and send a response backy
response = {
"status": "success",
"received_data": data,
"message": "JSON received and processed successfully"
}
emit('receive_json', response)
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5000)