Please go through this topic. There is a code in the loop which tries to reconnect every 10sec or so. This may solve the problem.