{"action":"created","issue":{"url":"https://api.github.com/repos/websockets/ws/issues/459","labels_url":"https://api.github.com/repos/websockets/ws/issues/459/labels{/name}","comments_url":"https://api.github.com/repos/websockets/ws/issues/459/comments","events_url":"https://api.github.com/repos/websockets/ws/issues/459/events","html_url":"https://github.com/websockets/ws/issues/459","id":59201881,"number":459,"title":"new public method setKeepAlive for WebSocket","user":{"login":"humingchun","id":2714046,"avatar_url":"https://avatars.githubusercontent.com/u/2714046?v=3","gravatar_id":"","url":"https://api.github.com/users/humingchun","html_url":"https://github.com/humingchun","followers_url":"https://api.github.com/users/humingchun/followers","following_url":"https://api.github.com/users/humingchun/following{/other_user}","gists_url":"https://api.github.com/users/humingchun/gists{/gist_id}","starred_url":"https://api.github.com/users/humingchun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/humingchun/subscriptions","organizations_url":"https://api.github.com/users/humingchun/orgs","repos_url":"https://api.github.com/users/humingchun/repos","events_url":"https://api.github.com/users/humingchun/events{/privacy}","received_events_url":"https://api.github.com/users/humingchun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-27T07:50:54Z","updated_at":"2015-03-03T10:04:45Z","closed_at":null,"body":"setKeepAlive is a great way to detect dead TCP connection and Node.js net module has a method called `socket.setKeepAlive([enable][, initialDelay])`.\r\n\r\nTo set keepalive in ws, we have to use `ws._socket` which is OK but not elegant. I would suggest adding setKeepAlive to ws so it clearly shows ws has the way to maintain a connection or detect dead connection.\r\n\r\nThe code could be\r\n```\r\nWebSocket.prototype.setKeepAlive = function setKeepAlive(enable, initialDelay) {\r\n  return this._socket.setKeepAlive(enable, initialDelay);\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/websockets/ws/issues/comments/76918081","html_url":"https://github.com/websockets/ws/issues/459#issuecomment-76918081","issue_url":"https://api.github.com/repos/websockets/ws/issues/459","id":76918081,"user":{"login":"humingchun","id":2714046,"avatar_url":"https://avatars.githubusercontent.com/u/2714046?v=3","gravatar_id":"","url":"https://api.github.com/users/humingchun","html_url":"https://github.com/humingchun","followers_url":"https://api.github.com/users/humingchun/followers","following_url":"https://api.github.com/users/humingchun/following{/other_user}","gists_url":"https://api.github.com/users/humingchun/gists{/gist_id}","starred_url":"https://api.github.com/users/humingchun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/humingchun/subscriptions","organizations_url":"https://api.github.com/users/humingchun/orgs","repos_url":"https://api.github.com/users/humingchun/repos","events_url":"https://api.github.com/users/humingchun/events{/privacy}","received_events_url":"https://api.github.com/users/humingchun/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T10:04:45Z","updated_at":"2015-03-03T10:04:45Z","body":"Great source for compare WebSocket ping/pong and TCP keepalive :+1: \r\n\r\nSo it's clear WebSocket ping/pong could do much more than TCP keepalive, and even more reliable. But in controlled network (like no HTTP proxy), use TCP keepalive to do dead-pear-detection is much more efficient than WebSocket ping/pong.\r\n\r\nI used this method when I am developing a IoT project which need to show the online status of real device. Using TCP keepalive intead of WebSocket ping/pong adds no coding to exising project and reduces the workload on device side."}}