doesn't it go to an infinite loop if the server cannot be connected? I would expected a counter or something like this which would be used to give up reconnecting after n times.