I am trying to create a "keepalive" websocket stream to send the emitter every 10 seconds to the browser as soon as someone connects to this page, but receives an error message and does not know how to get around it. Any idea how to make this work. And how can I kill this thread after sending the "disconnect"?
Thanks!
@socketio.on('connect', namespace='/endpoint') def test_connect(): emit('my response', {'data': '<br>Client thinks i\'m connected'}) def background_thread(): """Example of how to send server generated events to clients.""" count = 0 while True: time.sleep(10) count += 1 emit('my response', {'data': 'websocket is keeping alive'}, namespace='/endpoint') global thread if thread is None: thread = Thread(target=background_thread) thread.start()
python flask websocket flask-socketio
user1601716
source share