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 ) 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.
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/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.
- Did you test what happens when the server closes the connection gracefully by sending a close package? – Wutz Commented May 23, 2013 at 12:57
- Yes, if server closes connection, client got closeevent with closecode(sent by server) – raky Commented May 24, 2013 at 7:25
- chrome, ff in linux, network cable disconnected close dosen't trigger automaticaly – raky Commented Jun 18, 2013 at 10:39
1 Answer
Reset to default 7It 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.