了解机器何时连接到互联网
我正在使用java,所以我需要一种尽可能独立于操作系统的方法。我拥有的是一个每当计算机打开时就会运行的程序。我遇到的问题是当我需要通过互联网发送/接收文件时。我尝试将脚本放入 Windows 的启动文件夹和 Linux 的 rc0.d 中,它们工作正常,但前提是 wifi 已连接。我需要一种方法,仅在 wifi 完全连接并且功能正常后才运行该程序。我正在考虑使用类似 ping 功能来查看服务器何时启动,但我认为在互联网实际连接之前,用户不会高兴地在桌面上看到命令提示符框。 欢迎任何建议。
I am working with java so I would need a method which would be as operation system independent as possible. What I have is a program that will be running whenever the computer is turned on. The problem I am encountering is when I need to send/receive files over the internet. I tried putting a script in the startup folder for windows and rc0.d in linux, they work fine but only if the wifi is already connected. I need a way to only run the program after the wifi has been fully connected and it is functional. I was thinking to use like a ping function to see when a server is up but I am thinking that the users would not be happy to see the command prompt box on their desktop until the internet is actually connected.
Any suggestions are welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
理想情况下,您希望在互联网连接可用时收到通知,以便您可以对其做出响应,尽管这可能取决于操作系统。或者,定期向 Google 等进行 DNS 查找。如果成功,您就知道您的连接良好。我确信有一种方法可以在 Java 中轻松地做到这一点。
Ideally you would like to be notified when an internet connection is available so you can respond to it, though that is probably operating system dependent. Alternatively, just periodically do a DNS lookup to Google or something. If it succeeds you know you have a good connection. I'm sure there's a way to do it in Java easily.
InetAddress 可能是您的一个选择:
http:// /docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#isReachable
也许在定期检查连接性的线程中使用它,如果需要的话在一段时间后超时,并给出用户一些反馈。
InetAddress may be an option for you:
http://docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#isReachable
Maybe use this in a thread that periodically checks connectivity, times-out after a while if necessary, and gives the user some feedback.