miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
272 stars 24 forks source link

How would I handle on disconnect events? #79

Closed Krupskis closed 2 months ago

Krupskis commented 2 months ago

title

miguelgrinberg commented 2 months ago
from flask_sock import ConnectionClosed

@sock.route('/echo')
def echo(ws):
    try:
        while True:
            data = ws.receive()
            if data == 'close':
                break
            ws.send(data)
    except ConnectionClosed:
        print("disconnecting")    # <--- write your disconnect logic here
Krupskis commented 2 months ago

legend! thanks