[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Checking for Network Connection

Francis Cianfrocca

8/30/2006 6:30:00 PM

On 8/30/06, Matt Todd <chiology@gmail.com> wrote:
> OK, so, I quickly googled and was not able to find anything specific, but
> what I'm trying to do is find an elegant way to check for a network/internet
> connection. (I specifically need the internet, but a network connection
> needs to be preset as well for that... except for dial up? Gah.)
>
> So, from your collection experiences, what do you think is the best, most
> elegant way to check for a network connection or an internet connection?
> Should I just ping an address?
>
> And, sorry if I missed something obvious.
>
> M.T.
>
>

This isn't easy to do, in the general case. I assume you're just
trying to find out if you have a live connection to the WWW (including
firewall openings and DNS availability), so you could try this:


TCPSocket.new( "www.rubyforge.org", 80)

If it doesn't throw anything, you're golden. Make sure to add a
timeout loop (I usually wait no more than 4 seconds) because depending
on what is wrong, this call may hang for a long time. Don't use ping-
many firewalls block it.

4 Answers

Matt Todd

8/30/2006 8:16:00 PM

0

Thanks... that was also a solution I had thought about, but couldn't
really manifest with my limited experience.

I'm not exactly sure how to do a timeout loop... or, rather, what you
mean. Do you want me to try three times? Or perhaps to say "timeout
after this amount of time"? Is that part of TCPSocket#new ?

:D

M.T.

snacktime

8/30/2006 8:26:00 PM

0

I'm sure there is a timeout option for the socket call, or you could
just do something like this:

require 'timeout'
timeout(10) do
# connect
end

On 8/30/06, Matt Todd <chiology@gmail.com> wrote:
> Thanks... that was also a solution I had thought about, but couldn't
> really manifest with my limited experience.
>
> I'm not exactly sure how to do a timeout loop... or, rather, what you
> mean. Do you want me to try three times? Or perhaps to say "timeout
> after this amount of time"? Is that part of TCPSocket#new ?
>
> :D
>
> M.T.
>
>

Matt Todd

8/30/2006 8:44:00 PM

0

> I'm sure there is a timeout option for the socket call, or you could
> just do something like this:
>
> require 'timeout'
> timeout(10) do
> # connect
> end

Sweet! I didn't know that library existed! You learn something new every day.

Thanks guys.

M.T.

Steve

8/23/2010 4:10:00 PM

0

On Mon, 23 Aug 2010 11:02:01 -0500, "5660 Dead, 803 since 1/20/09"
<deadis@deadduz.com> wrote:

>On Mon, 23 Aug 2010 06:50:33 -0700, Phlip wrote:
>
>> On Aug 22, 12:46?am, D?nk 666 <dank...@rocketmail.com> wrote:
>>> On Aug 21, 10:32?am, "5646 Dead, 789 since 1/20/09"
>>>
>>> <dea...@deadduz.com> wrote:
>>> > Assange was in Sweden last week partly to apply for a publishing
>>> > certificate to make sure the website, which has servers in Sweden,
>>> > can take full advantage of Swedish laws protecting whistle-blowers.
>>>
>>> > He also spoke at a seminar hosted by the Christian faction of the
>>> > opposition Social Democratic party and announced he would write
>>> > bimonthly columns for a left-wing Swedish newspaper.
>>>
>>> Now if only he was a member of the Duke University lacrosse team, then
>>> you would be calling for his head on a stick.
>>
>> You are comparing him to a spoiled brat with a history of abusing women?
>
>I think Danky is too crazy to know what he thinks of Assange. He just
>thinks that attacking him will annoy me.


It's pretty easy to annoy Zepp. Just mention that he wears adult
diapers.
--
....watching Obamma supporters wimp and whine about the economy... PRICELESS