make number of retries in ensure_connected configurable

Instead of retrying only once on connection failures,
have a config option in the client to specify how
many attempts should be made.