Solved

checking internet connection

Posted on 2003-11-01
7
259 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:vjayaprasen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 9662541
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
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9663528
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
 
LVL 32

Expert Comment

by:jhance
ID: 9663872
Martyn,

You may want to study what these APIs actually do before recommending them in a situation like this...
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9665710
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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question