最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - websocket onclose not triggered in chrome - linux when client is disconnected from the network - Stack Overflow

programmeradmin0浏览0评论

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.

Share Improve this question edited Sep 25, 2013 at 12:12 BartoszKP 35.9k15 gold badges107 silver badges134 bronze badges asked May 23, 2013 at 12:23 rakyraky 1911 gold badge2 silver badges11 bronze badges 3
  • 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
Add a ment  | 

1 Answer 1

Reset to default 7

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论