Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Apr 25, 2017 11:31 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Check for internet connection (Windows OS Only)
PostPosted: Sat Feb 11, 2012 2:19 pm 
Offline

Joined: Sat Mar 12, 2011 9:18 am
Posts: 71
1. Add the following function to a module
Function Check(aWebsite As String) As Boolean
Const FLAG_ICC_FORCE_CONNECTION = &H1
Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" ( lpszUrl As CString, dwFlags As Integer, dwReserved As Integer ) As Integer

If InternetCheckConnection(aWebsite, FLAG_ICC_FORCE_CONNECTION, 0) = 0 Then
Return False
Else
Return True
End If
End Function


2. Call the function anywhere in your app like this:
If Check("http://www.mdsn.com") = True Then
MsgBox "Internet Connection Available!"
Else
MsgBox "Internet Connection Not Available." + EndOfLine + "Maybe a firewall is blocking this executable?"
End If


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Sat Feb 11, 2012 5:08 pm 
Offline
User avatar

Joined: Wed Oct 06, 2010 10:25 am
Posts: 154
Location: ---
Good tip! I will try It.
Thanks a lot.
Regards,
Max.

_________________
Massimiliano Fabbri
Freelance Senior Programmer
(Eudosia Systems)
Visual Basic 6 - RealStudio - Mobile Development
Php5/Mysql - Dot Net C# - Objective C
-------------------------------------------
http://www.eudosia-systems.it


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Sun Feb 12, 2012 5:17 pm 
Offline

Joined: Thu May 08, 2008 2:26 am
Posts: 82
Simple ping over a shell works with any OS.... much easier

_________________
Graphic-BevelButton Class: MDButton
RealStudio (2008R1) & 2011R4 PRO (Win/Mac)
Windows 7 x64 Ultimate / Mac OSX 10.8


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Fri Feb 24, 2012 4:32 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Paulemann wrote:
Simple ping over a shell works with any OS.... much easier

Can you please explain what you mean to say?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Fri Feb 24, 2012 5:07 am 
Offline

Joined: Wed Dec 14, 2011 4:20 am
Posts: 84
Paulemann wrote:
Simple ping over a shell works with any OS.... much easier



Well ping might work for some hosts. But some companies block ping in the firewall.


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Fri Feb 24, 2012 6:09 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
amitavak wrote:
Paulemann wrote:
Simple ping over a shell works with any OS.... much easier

Can you please explain what you mean to say?

Actually I can't understand what is "ping"? I never heard it before.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Fri Feb 24, 2012 11:27 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Google is your friend http://en.wikipedia.org/wiki/Ping


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Fri Feb 24, 2012 9:45 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Some more handy functions:

Function InternetAvailable() As Boolean
//Returns True if the computer appears to have Internet access.
//Windows Vista and newer only
If System.IsFunctionAvailable("IsInternetConnected", "Connect") Then
Soft Declare Function IsInternetConnected Lib "Connect" () As Integer
Return IsInternetConnected = 0
End If
End Function


Function IsDestinationReachable(destination As String) As Boolean
//Attempts to contact the destination server. Do not include the protocol (e.g. "http://") just the server name, IP address, or UNC path.
//Windows 2000 and XP only.
If System.IsFunctionAvailable("IsDestinationReachableW", Lib "SensAPI") Then
Soft Declare Function IsDestinationReachableW Lib "Sensapi" (destination As Wstring, ByRef info As QOCINFO) As Boolean
Dim info As QOCINFO
info.sSize = info.Size
Return IsDestinationReachableW(destination, info)
End If
End Function

The QOCINFO structure for the above functionis defined as follows:
Structure QOCINFO
sSize As Integer
flags As Integer
inSpeed As Integer
outSpeed As Integer



Function NetworkAvailable() As Boolean
//Returns True if at least one network connection is alive. This does not neccessarily mean that Internet access is available.
//On error, or if no connections are alive, returns False.
//Works on Windows 2000 and newer
Declare Function IsNetworkAlive Lib "Sensapi" (ByRef netFlags As Integer) As Boolean
Declare Function GetLastError Lib "Kernel32" () As Integer
Dim flags As Integer
If IsNetWorkAlive(flags) Then
If GetLastError = 0 Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function


These functions are part of a larger collection I have put together.

_________________
Boredom Software


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Sun Feb 26, 2012 5:34 am 
Offline

Joined: Sat Mar 12, 2011 9:18 am
Posts: 71
Great addition charonn0


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Thu Jul 12, 2012 6:02 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Hi charonn0,

Your functions are working great on windows.

But I need a platform independent solution. Do you have any suggestion?

Thanks

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Thu Jul 12, 2012 11:38 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Sorry, nope. Windows is my bailiwick.

_________________
Boredom Software


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Thu Jul 12, 2012 11:41 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
PING is platform independant... . OSX and Windows both include a PING utility...

And if all you are looking for is Internet Connectivity.... just PING GOOGLE...

Not going to give you all the code..... but use SHELL and look up ping on Google if you don't know what it is...


(not sure how anyone can have done any kind of internet/network stuff and still not know PING... but ok)

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
 
 Post subject: Re: Check for internet connection (Windows OS Only)
PostPosted: Sun Jul 29, 2012 10:53 am 
Offline

Joined: Sat May 17, 2008 9:14 pm
Posts: 70
I'm joining this thread a little late, but here's my $.02

I'd use ping as has already been suggested, but instead of pinging google or any other url, I'd ping at least 1 if not 2 different root (DNS) servers by IP address (https://www.iana.org/domains/root/servers).

Why? Because your internet connection could be up but google could be down and as such not responding to pings. Or, your dns could be down and unable resolve the IP that needs to be ping'd.

If you really want/need to, you could then take the next step and test DNS resolution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group