Websocket onclose does not start in chrome-linux when the client is offline

I implemented websocket using java on server side. In the client, I created the websocket object, and I have my own function for all events, including onClose. I tested reconnection ... websocket in chrome 26, Mozilla and windows and chrome.

Chrome in windows fires an event when I plug in a network cable (i.e. onclose triggers with closed code 1006 [abnormaly closed] , as stated in https://developer.mozilla.org/en-US/docs/Web/API/ CloseEvent ), but Chrome on linux does not raise any events.

Please suggest what mistake I made.

My exact question is why chrome in windows starts onclose when the network is disconnected, but in case of Linux it does not start.

+4
source share
1 answer

Perhaps these applications do not notice a broken TCP connection. The timeout is used to detect a TCP connection failure, and I believe that the default timeout is quite long.

In the browser / OS, it should be noted that the connection is lost as soon as you try to send data. Try sending some data after disconnecting the network cable, see if this event fires.

Also, how long have you been waiting for the signal? The connection may have a long TCP timeout.

If you still do not receive a private event, this is probably due to an implementation error. If you absolutely need to know when the connection will break, use the ping mechanism with your timeout. I believe the websocket protocol defines its own ping protocol, maybe study this.

Also, for chrome, it seems for issue . Perhaps this will help you.

+3
source

Source: https://habr.com/ru/post/1482380/


All Articles