Using a socket, I know I can get a response to a post message.
I know I can trap a ‘connected’ event when it connects.
I’d like to know if an internet connection is available before I try rather post and sitting waiting for a ‘train that won’t come’
Is there a way to know if an internet connection is available?
On some machines, white or blacklisting can prevent my app from dialling home.
I found out about this just the other day, Network.IsConnected
Thats a handy tip.
I’ll probably still need to check if that tells me about my own app, or the machine as a whole.
I guess a LAN will get you Network.IsConnected = True
, but it won’t say the Internet is present. Checking if Internet connectivity exists remains necessary.
On that page it notes that: This function is supported on Linux.
I have not tried it, but this looks like either an implication that it is only supported on Linux or it is a documentation oddity.
[quote=231042:@Chris Carter]On that page it notes that: This function is supported on Linux.
I have not tried it, but this looks like either an implication that it is only supported on Linux or it is a documentation oddity.[/quote]
It works fine on Mac. But as I suspected, it just reports the presence of connectivity. A local router is seen as network.
To make sure the Internet is present, the simplest I found is to shell
ping google.com
If there is no Internet, result is :
ping: cannot resolve google.com: Unknown host
otherwise it gives something like :
PING google.com (216.58.211.78): 56 data bytes
64 bytes from 216.58.211.78: icmp_seq=0 ttl=55 time=25.279 ms
In Windows,
Ping request could not find host google.com. Please check the name and try again
or
Pinging google.com [173.194.45.46] with 32 bytes of data:
Reply from 173.194.45.46: bytes=32 time=25ms TTL=55
Seems like a nice cross platform way.
I found that just asking for my homepage with an httpsocket.GET with a timeout looks like the easiest way to check.
If I get a status of 200, the site is there, and I can talk to it, so I can then proceed to risk a POST.
dim h as new HTTPSocket
call h.Get("http://www.example.com/", 30)
if h.HTTPStatusCode <> 200 then
msgbox "There may be trouble ahead, but while there's moonlight..."
end if
And what about:
Dim http As New HTTPSocket
HTTP.Address = “www.apple.com”
http.port = 80
http.Connect
if http.LastErrorCode = 0 then
//do something
//MsgBox “Connected”
end if
http.close
It SEEMS quicker that Jeff’s code. But is it 100% reliable?
Thanks.