Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Test for Internet Connection

Reply
Thread Tools

Test for Internet Connection

 
 
Cory Cory
Guest
Posts: n/a
 
      03-17-2008
Does anyone know a way to test to see if the computer is connected to
the internet in Ruby?

I wrote a Ruby program with WWW::Mechanize, but it completely hangs Ruby
when my internet is turned off. Because Ruby does not use system
threading, there is no way to check for a timeout when WWW::Mechanizer
freezes due to not having an internet connection.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Pascal J. Bourguignon
Guest
Posts: n/a
 
      03-17-2008
Cory Cory <(E-Mail Removed)> writes:

> Does anyone know a way to test to see if the computer is connected to
> the internet in Ruby?
>
> I wrote a Ruby program with WWW::Mechanize, but it completely hangs Ruby
> when my internet is turned off. Because Ruby does not use system
> threading, there is no way to check for a timeout when WWW::Mechanizer
> freezes due to not having an internet connection.


require 'ping'
Ping.pingecho("google.com",10,80) # --> true or false

--
__Pascal Bourguignon__
 
Reply With Quote
 
 
 
 
Cory Cory
Guest
Posts: n/a
 
      03-17-2008
> require 'ping'
> Ping.pingecho("google.com",10,80) # --> true or false


This did not work. The same exact problem occurred: Ruby froze and
there was no way to unfreeze it besides connected to the internet or
force quit.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Roger Pack
Guest
Posts: n/a
 
      03-17-2008
I usually do something like this on my machine

loop do
break if system("ping google.com")
sleep 1
end
puts "Internet working!"

Cory Cory wrote:
> Does anyone know a way to test to see if the computer is connected to
> the internet in Ruby?
>
> I wrote a Ruby program with WWW::Mechanize, but it completely hangs Ruby
> when my internet is turned off. Because Ruby does not use system
> threading, there is no way to check for a timeout when WWW::Mechanizer
> freezes due to not having an internet connection.


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Avdi Grimm
Guest
Posts: n/a
 
      03-17-2008
On Mon, Mar 17, 2008 at 9:32 AM, Cory Cory <(E-Mail Removed)> wrote:
> Does anyone know a way to test to see if the computer is connected to
> the internet in Ruby?


What OS?

--
Avdi

 
Reply With Quote
 
Cory Cory
Guest
Posts: n/a
 
      03-17-2008
Roger Pack wrote:
> I usually do something like this on my machine
>
> loop do
> break if system("ping google.com")
> sleep 1
> end
> puts "Internet working!"


Even that caused Ruby to hang.
I am using Ubuntu.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Roger Pack
Guest
Posts: n/a
 
      03-17-2008
require 'resolv-replace'
might help, or google for ruby asynchronous dns
I know rev has one, and also there is a package for eventmachine that
does it.

The problem is that when it does DNS lookup it hangs forever (I'd
imagine) waiting for a response.

This might help it.

loop do
break if system("ping 64.233.187.99")
sleep 1
end
puts "Internet working!"


GL.
-R

Cory Cory wrote:
> Roger Pack wrote:
>> I usually do something like this on my machine
>>

>
> Even that caused Ruby to hang.
> I am using Ubuntu.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Avdi Grimm
Guest
Posts: n/a
 
      03-17-2008
On Mon, Mar 17, 2008 at 11:08 AM, Cory Cory <(E-Mail Removed)> wrote:
> I am using Ubuntu.


AFAIK the "right" way to test for a network connection on Ubuntu is to
use the NetworkManager D-Bus interface. I believe there is a D-Bus
library for Ruby. A quick google for the NetworkManager D-Bus API
yields this: http://people.redhat.com/dcbw/Networ...DBUS%20API.txt

--
Avdi

 
Reply With Quote
 
Cory Cory
Guest
Posts: n/a
 
      03-17-2008
> use the NetworkManager D-Bus interface. I believe there is a D-Bus
> library for Ruby. A quick google for the NetworkManager D-Bus API
> yields this:
> http://people.redhat.com/dcbw/Networ...DBUS%20API.txt


The ruby-dbus package is still being developed. Most importantly, it is
not available in any deb package list. This means I cannot write code
that would be very portable with this.

Any other suggestions?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Avdi Grimm
Guest
Posts: n/a
 
      03-17-2008
On Mon, Mar 17, 2008 at 12:45 PM, Cory Cory <(E-Mail Removed)> wrote:
> The ruby-dbus package is still being developed.


This describes nearly every Ruby library in existence.

> Most importantly, it is
> not available in any deb package list. This means I cannot write code
> that would be very portable with this.


sudo gem install dbus

If you are depending on only libraries that are deb-packaged, your
code will neither be portable (to non-deb linuxen) nor will you be
able to take advantage of many Ruby libraries (since very few are deb
packaged).

--
Avdi

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
test test test richard Computer Support 3 01-24-2007 05:18 AM
TEST TEST Test...Blah Blah Blah generalbatguano@pacbell.net Computer Support 2 09-15-2006 03:47 AM
TEST TEST Test...Blah Blah Blah Generalbatguano@pacbell.net Computer Support 6 09-13-2006 01:53 AM
TEST TEST TEST Gazwad Computer Support 2 09-05-2003 07:32 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments