technically you cannot prevent a disconnection. websockets were introduced to avoid your "ping" suggestion, which was one way to address the matter. the original http protocol built a disconnect in as part of the design. http 1.1 went the opposite way and allowed for the connection to stay open. but once a disconnect occurs, it's up to the client to try to make contact again. in the case of websockets, your client software might notice and inform you. you'd have to check the spec, but i think generally, you won't know until you try to talk to the server and time out on any response.