简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM