HenkKaasman
HenkKaasman

Reputation: 55

Raspberry Pi java wifi checker

I have a virtual router on my laptop that my raspberry pi is connected to. It runs a couple of java processes that I need to keep track off, so if it disconnects I want to make it stop working, so:

while(true){
    if(WifiChecker())
        return;
    //do rest
}

Is there a way to accomplish this? If possible I would also like something easy that makes it reconnect to my virtual wifi, though that is not necessary.

Upvotes: 1

Views: 867

Answers (1)

mhlz
mhlz

Reputation: 3547

Just try pinging the IP Address of that virtual router or alternatively some address on the internet (Google or similar big sites are great for this since they're probably not going to be down).

You can use Java sockets for that, but you will need root access as pointed out in the most upvoted answer of this thread about pinging with java.

Alternatively you can use a ProcessBuilder to start the ping utility itself and examine its output and/or error code.

Upvotes: 1

Related Questions