Connect and disconnect as needed to avoid timing out.