简体   繁体   中英

how to flash messages emit by flask_socketio?

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;
            });

events.py

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM