I can not use flask flash messages sent with emit and "captured" with @socketio.on, but it works on the html page. How to fix flash from flask_socketio ? When i look in terminal, it works. it's at the jonction socket / flash that the problem is .
$('form#send_room').submit(function(event) {
socket.emit('my_room_event', {room: $('#room_name').val(), data: $('#room_data').val()});
return false;
});
@socketio.on( 'send_room' , namespace='/roomy/roomy')
def broadcast_info_new_box(data):
print("\n\n\n broadcast_info_new_box called with socket on landing events.py")
flash(data)
The flash()
function works only in Flask routes, as it relies on an HTTP response delivering an updated session cookie to the client. You are trying to use it in a Socket.IO event handler, which does not have a way to send cookies to the client.
If you want to implement alert popups or similar via Socket.IO you will have to emit these alerts as events to the client, and then use JavaScript in the client to display them.