Open rreghin opened 10 years ago
Well, I worked a way around the problem.
Instead for using the close() method, I made a command to disconnect the client from the server side. So when the client wants to disconnect, it sends the "disconnect me" command to the server, and the server does the job.
Solved my problem, but I still wonder why the close() method would not work...
Hi, rreghin I find the same issue, on my android device (4.0.4). I use ws (https://github.com/einaros/ws) as my websocket server.
The weird thing is that even the device is disconnected, when the server tries to send some message to the device, there is no error and the server still has no idea about the dead connection.
That's very odd. =(
Unfortunately I have no idea on how to help you.
Did you try to do the workaround I mentioned in my last post (May 23) ??
Yes, I tried. Did you find the same issue that when the device disconnects (before sending "disconnect me" message), the server could still "send" message with the disconnnected websocket connection? I really hope that when the server tries to send something, there would be a error if the connection is already disconnected.
Yes, I had the same problem. Actually, I think this is some "TCP/IP stack" feature/issue, and I think it has nothing to do with the WebSockets itself.
Its up to the client to send a FIN packet to the server whenever it wants do disconnect. If the client does not send the FIN packet, the server has no way to know the connection is dead.
The socket function close(fd) is supposed to do the job, and I think it does it very well. But sometimes for some reason, like a network problem, the server does not receive the FIN packet. But what I think is more likely to happen is the client sends the FIN packet, the server receives it and then reply to it (with an ACK packet), as expected, but the client is already gone and won't reply back to the ACK packet. Then boom, you're server side connection is stuck in a FIN_WAIT_2 state, and there's not much you can do about it.
I solved this problem with a server keep alive packet. My server sends a tiny packet to the client every 1 or 2 minutes, and when it gets no response from the client after 2 consecutive packets it just drops the connection.
Hope it helps somehow... =)
Thank you for your explanation. This really helps me a lot to understand my problem.
Hello again!
I'm having a hard time trying to figure out why the close() method is not working properly.
When using the browser's native version of WebSocket, or the Android's 4.4.x native version (fallback) as well, the close() method works as expected, and it closes the connection right away.
But when using your plugin, it takes forever to close the connection, and eventually the server will close the connection due to innactivity.
Should I do something else other than simply calling the close() method (function) of the object??