I’m building a FastAPI server that communicates with a Flet front-end via WebSocket. I need the server to detect if the client disconnects improperly (e.g., the app crashes or the network connection is lost).
I tried this code:
while str(websocket.application_state) == 'WebSocketState.CONNECTED':
pass # do something
But the while loop never finished even when I closed the app improperly myself.
What should I do?
Thanks!