Add retries

Add logic for retrying connection when a connection refused exception occurs.