I implemented websocket by using java in server side. In client I created websocket object, and I have my own function for all the events including onClose. I tested reconnection... websocket in chrome 26, Mozilla both windows and chrome.
Chrome in windows triggers onclose event when I plugged out the network cable (i.e onclose
triggers with closecode 1006 [abnormaly closed]
as mentioned in https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) but Chrome in linux does not trigger any event.
Please suggest what mistake I did.
My exact question is why chrome in windows triggers onclose
when network is disconnected, but in case of linux, it is not triggered.
It is possible that these applications do not notice the TCP connection breaking down. A timeout is used to detect a failing TCP connection, and I believe the default timeout is quite long.
The browser/OS should notice that the connection is gone as soon as you try to send data. Try sending some data after unplugging the network cable, see if that triggers the event.
Also, how long have you waited for the signal? Maybe the connection just has a long TCP timeout.
If you still do not get a closed event it is likely due to a fault in the implementation. If you absolutely need to know when the connection breaks down, implement a ping mechanism with your own timeout. I believe the websocket protocol defines its own ping protocol, maybe look into that.
Also, for chrome there seems to be an issue filed for this. Maybe it'll help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With