I wrote an application to start my server at home remotely. The application works without problems in the emulator, as well as on my smartphone (HTC desire, Android 2.2) when WiFi is on. However, this does not work when WiFi is off.
Before rebooting, first check if it is running. For this, I use sockets, and I first connect to the dyndns address. After that, I try to connect to my ip-box, where I can turn on my computer by sending commands through the socket.
When the connection to this socket fails, I know that the server is not running.
Relevant Code:
socket = new Socket(); socket.connect(new InetSocketAddress(serverName, port), 10000); status = socket.isConnected() == true; socket.close();
If an exception (SocketException) exists, I know that the server is not running. This approach works fine when I turned on WiFi. However, if Wi-Fi is not turned on, the connection always talks about it, even if it cannot establish a connection because the server is unavailable.
Is there a way to check if the connection is established even if WiFi is disconnected?
Any suggestions are welcome!
Thanks,
Rudy
Rudolf ziegaus
source share