How to check for internet connection using Ruby.
Asked
Active
Viewed 2,109 times
2
-
Why do you need to? You should add more detail, because this will get downvoted as it is – Elizabeth Buckwalter Oct 29 '09 at 06:48
-
Also let us know which platform you're on. Detecting a connection to the internet depends on the platform. Even then you wouldn't be able to distinguish an internet connection from a network connection without sending any packets – EmFi Oct 29 '09 at 07:08
-
Sorry for not being detailed. I am trying to code an app to fetch an XML file from a website. Intended platform will be Win32. – rƒc Oct 29 '09 at 21:50
2 Answers
1
Using Ping
is deprecated in Ruby 1.9.x as explained here: https://stackoverflow.com/a/8317838
A more future-proof, as well as more code-relevant solution would be the solution given by that answer, using open-uri
and returning false on exception.