Sync Timeout

I developed an app to send data every 30 second to a server via wi-fi directly.
But if the app can not find the server, (for example the server is temporary down) it can not handle the situation. when something like this happen it shows the "searching for wifi page constanly"
It is connected to wi-fi. Even if the server back online it stuck in this step.

Is there any way to put a Timeout for Sync and makeWebRequest?