Always test connectivity with an http request after a websocket closes, regardless of what code/error it closed with. If that request succeeds, automatically reconnect the socket. // FREEBIE