Added detection of socket close, at which point heartbeat messages are stopped to keep everything clean. This is relevant particularly for laptops that have their network interrupted intermittently.