Checking internet connection

For the time being I’ve got this implemented now. As far as I tested and measured this consumes the lowest cpu-time.

[quote] // polling in seperate thread

mPollingReady = false
Dim TCPSocket1 As New TCPSocket
TCPSocket1.Address = mPollUrl // 173.194.67.138 = google
TCPSocket1.Port = 80
TCPSocket1.Connect
While Not TCPSocket1.IsConnected
If TCPSocket1.LastErrorCode <> 0 then Exit
TCPSocket1.Poll
Me.Sleep(100,false)
Wend
InternetConnected = TCPSocket1.IsConnected
mPollingReady = True
TCPSocket1.Close[/quote]

I’ve tweaked the code by @Wayne Golding to properly work on the Mac (his code had long delays if the connection was offline):

[code]Public Function IsOnline() as Boolean
Dim sh As New Shell
sh.Mode = 0

#If TargetWindows Then
sh.Execute(“ping ns1.google.com -n 1”)
If InStr(0, sh.Result, “Pinging”) > 0 Then Return True
#ElseIf TargetMacOS
sh.Execute(“ping ns1.google.com -c 1 -t 2”)
If Instr(0, sh.Result, “ns1.google.com ping statistics”) > 0 Then Return True
#ElseIf TargetLinux
sh.Execute(“ping ns1.google.com -c 1”)
If Instr(0, sh.Result, “ns1.google.com ping statistics”) > 0 Then Return True
#EndIf

Return False
End Function[/code]

Note the -t 2 flag for the Mac which specifies to bail after 2 seconds if no packet is received.