Implement retry in connecting to server