Replies: 1 comment 6 replies
-
When the user disconnects the receive and send functions should raise an exception. Have you seen that? I'm not sure you need to work with timeouts to detect users going away. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi miguelgrinberg,
i have a program, which connect to users home's Wi-Fi network, after that it creates an asyncron webserver on port 80. Currently i have 6 separate websites. When you open the website, the webserver sends out the html file, which contains every java scripts. After that, every website creates two websockets. The first one always waiting to receive data, second one is always sends time datas then gets back a message and send again every 2 seconds.
If the user disconnects from the home network, the program able to stuck inside the websocket function.
It is important: The microcontroller doesn't disconnect from the Wi-Fi, just the user disconnects from the home Wi-Fi network with phone or tablet.
I have implemented a solution for this: i always check the timeouts inside the websockets with await asyncio.wait_for().
If the second websocket runs to timeout i close it with ws.close(). Inside the first websocket i always check timeouts also and this websocket knows when the state of the second websocket.(via a variable) If the first runs to timeout, it checks the indicator variable value.
If this value is 0, that means second is at open state so the first webserver goes back to waiting to receive message. If the value is 1, i close the first websocket also.
Do you have any other solution, how can i correct this behavior of the websocket, because my solution i think its not the perfect, because sometimes able to freeze with that solution also.
Here is my code:

The websocket waiting to a message for 1 sec, if it runs to timeout its checking a variable.(This variable inside a class, and i can change it with the times.change_websocket_time_error_indicator() function. Every website has an own variable inside the class. If this variable 0, the websocket goes back to wait to receive message. If its 1, i close it and change back the variable to 0. The reason is this closing happen when i go to other website.
First websocket:
Second websocket:

Its sends the datas after get back an ok message then send datas again. If it runs to timeout, it changes the indicator value to 1.
Thank you in advance for your answers.
Beta Was this translation helpful? Give feedback.
All reactions