473,804 Members | 4,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test connection with internet



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
1 2927
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.Cre ate("http://www.google.com" );

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

if(wresp.Status Code == HttpStatusCode. OK)
{
blnConnected = true;
}
}
catch(System.Ne t.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2810
by: Peter Flynn | last post by:
I'm having trouble finding example code to detect the presence of an Internet connection. It doesn't seem to be a very frequently asked question, as all I need is the answer yes or no (is the user connected or not). I'm not interested in speed detection or any other aspect of the connection, just its existence or not. The reason is to be able to intercept link clicks on a CD-based set of HTML pages and pop up a warning if there is no...
3
6643
by: Jonny | last post by:
Hi, Please could you tell me how to check for an internet connection in C. I'm using Windows 2000. Many Thanks, Jonny
0
278
by: Ricardo Luceac | last post by:
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...
2
2429
by: Mahesh Devjibhai Dhola | last post by:
Hi, I want to develop p2p (peer-to-peer) communication connection for chat in ..Net (Lang: c# - preferable) NOTE: if two LAN are behind their own router then also it should work as yahoo, msn messenger works. Let me explain scenario: In yahoo: - We login to yahoo server from yahoo messenger (yahoo server listens at
15
27772
by: ezmiller | last post by:
Does anybody know how to use javascript to test whether or not an internet connection exists? Is this possible even?
4
8467
by: John Riddle | last post by:
Hello, I have an application that runs continously gives an error and stops working if the internet goes down (which happens for about 5-10 minutes several times a day. Can anybody tell me how to test for internet connectivity when this happens and then pause processing until internet connectivity is back up? Thanks.
4
1578
by: adalton | last post by:
I've been trying to figure out how to test for a valid internet connection. I am able to connect to a valid internet connection, but when it drops, or if it is not there when my program starts, I get an exception. This probably is a newbie question, but I do not even know what or how I would trap that error.
3
4050
by: danielmcinerney | last post by:
i am trying to set up internet connection sharing between a vista machine (host) and an XP machine (client). i have followed guidelines from various pages on the internet but i still cannot get it working. here is what ive done i gave up on using dhcp addressing between the host and client as this wasnt working so i tried using static ip's instead. the host and the server are connected by a wired connection (through a switch). the host is...
1
2269
by: =?Utf-8?B?QiBTaW5naA==?= | last post by:
Hi Scenario 1) Host - XP Laptop with internet connection using Sky Broadband Wireless Router Netgear DG834GT 2) MS Virtual Server 2005 - I have deployed an XP MS Virtual Server 2005 to act as a virtual machine
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.