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?
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:
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.
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 ?