Is Network Active
Written by Kevin Cloutier on Nov 2, 2017 10:13 am
If your application is set to start on boot then there is a chance that it will start executing before the network is ready. Add this simple check before you perform any critical network tasks.
if (!Network.isActive()) {
System.out.println("Waiting for network");
while (!Network.isActive()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.err);
}
}
}
System.out.println("Network Ready");
On this page