checking internet connection

hi guys,
 i need to check whether the internet connection is available or not.i tried RAS APi and some method.but none of them are not reliable.
is there any alternative method for that one...
thx in advance
regards
prakash
vjayaprasenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
There is no such thing as an "internet connection".  The internet is a concept not a thing to be connected to.

What you are therefore asking is impossible to answer.

What I THINK you are asking, but am somewhat unsure due to the ambiguity in your question is:

"How do I know if my computer is actively connected to some network that can reach a remote host?"

If that is really your question then I have some suggestions.  But how to proceed depends on HOW you connect your computer to a network.  There are TWO basic ways:

1) DIAL UP (in Windows terminology, RAS)

2) Wired (or WIRELESS) LAN

Any other type you think you have really is based on one of these two.

1) If you are interested in RAS, the RAS API will tell you EVERYTHING you need to know about the specific RAS connection.  What is will NOT tell you is whether or not you can connect to some remote host.  The ONLY way to know that is to TRY IT.  If it works, the answer is YES, if it fails the answer is NO.  Got it?

2) If you are interested in LAN, there is not a GENERAL Windows API for this.  Different versions of Windows have different capabilities.  So without knowing your platform, I can't give you any specific advice other than to first determine if you are operating in RAS connection.  If not, then a LAN connection is possible.  To determine if you can connect to a remote host or not, use the SAME method as with RAS.  TRY the connection and see if it works.

Keep in mind that even if the connection works NOW, it may NOT work later.  Networks are funny things and they come and go as they please.  So if you are building some application that depends on some sort of network connection, you MUST employ coding practices that anticipate network failure at ANY TIME.  To do otherwise will make your application unstable and very annoying to your users.

If I've misinterpreted your question, please clarify yourself.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
martynjpearsonCommented:
You might want to check out the API functions InternetGetConnectedState() or InternetCheckConnection(). See
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetgetconnectedstate.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetcheckconnection.asp

Hope this helps
Martyn
0
jhanceCommented:
Martyn,

You may want to study what these APIs actually do before recommending them in a situation like this...
0
martynjpearsonCommented:
I have to admit my suggestion about using InternetGetConnectedState() was based on some research I did onto the problem when wishing to do something similar in one of my own applications, rather than actual experience. I've had a hunt and found the document I found when looking into the problem before :

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q242/5/58.ASP&NoWebContent=1

It describes the use of the function, however, the article does say exactly what you said above - the only way to be sure there is a connection is to try and use it.

Best regards
Martyn
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.