0

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.

user1198778
  • 379
  • 1
  • 4
  • 10
  • You also need to take into account firewalls, anti-virus software that block "unauthorized" network access by processes etc. – eternaln00b Feb 09 '12 at 05:01
  • *"I need a way to only run the program after the wifi has been fully connected and it is functional"* Given the user might stop the network connection the moment after the app. launches, it makes more sense to `try`/`catch` around each net access. – Andrew Thompson Feb 09 '12 at 05:37

2 Answers2

1

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.

Bojin Li
  • 5,769
  • 2
  • 24
  • 37
0

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.

eternaln00b
  • 1,043
  • 9
  • 18