By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Test connection with internet

P: n/a


HI...

I'm making a program to test f my connection to the internet was
alive... I think of make a webrequest and ersponse, but even if my
connection is down doesn't I get a response??? The error 404...

Does you all have an Idea how can I do that???
thx...

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Ricardo,
if you want to use a webrequest and response to test the internet
connection you could do something like the following, you know that you are
not connected because you will not be alble to resolve the web url and an
exception will be thrown:

bool blnConnected = false;

//choose a site you can count on be up most of the time
HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://www.google.com");

try
{
//try to get response from the website
HttpWebResponse wresp = (HttpWebResponse)wr.GetResponse();

if(wresp.StatusCode == HttpStatusCode.OK)
{
blnConnected = true;
}
}
catch(System.Net.WebException exc)
{
//this will happen if you cannot connect to the site
blnConnected = false;
}
finally
{
wresp.Close();

if(blnConnected)
{
//do connected action
}
else
{
//do unconnected action
}
}
"Ricardo Luceac" wrote:


HI...

I'm making a program to test f my connection to the internet was
alive... I think of make a webrequest and ersponse, but even if my
connection is down doesn't I get a response??? The error 404...

Does you all have an Idea how can I do that???
thx...

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.