简体   繁体   English

Raspberry Pi Java wifi检查器

[英]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: 它运行了几个我需要保持跟踪的Java进程,因此,如果断开连接,我想使其停止工作,因此:

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. 如果可能的话,我也希望有一些简单的方法可以使它重新连接到我的虚拟wifi,尽管这不是必需的。

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). 只需尝试ping该虚拟路由器的IP地址或Internet上的某个地址即可(Google或类似的大型站点非常适合此操作,因为它们可能不会宕机)。

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 . 您可以为此使用Java套接字,但是您将需要root访问权限,如该线程有关使用ping通Java的最受好评的答案所指出的那样。

Alternatively you can use a ProcessBuilder to start the ping utility itself and examine its output and/or error code. 或者,您可以使用ProcessBuilder来启动ping实用程序本身,并检查其输出和/或错误代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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