Added heartbeat and reconnect functionality in the client