5

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.

4

1 回答 1

4

这些应用程序可能没有注意到 TCP 连接中断。超时用于检测失败的 TCP 连接,我相信默认超时是相当长的。

一旦您尝试发送数据,浏览器/操作系统应该会注意到连接已经消失。拔下网线后尝试发送一些数据,看看是否会触发事件。

另外,你等了多久的信号?也许连接只是有很长的 TCP 超时。

如果您仍然没有收到关闭的事件,则很可能是由于实施中的错误。如果您绝对需要知道连接何时中断,请使用您自己的超时实现 ping 机制。我相信 websocket 协议定义了自己的 ping 协议,也许可以看看。

此外,对于 chrome,似乎存在一个问题。也许它会帮助你。

于 2013-06-18T15:50:42.740 回答