WSAECONNREFUSED means, the server is not accepting your connection request.
You will have to retry to connect in a loop with sleeping a few seconds between the retries. There is no way for the client to know when the server is available again, without trying to connect.