Skip to content

Is Network Active⚓︎

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");