Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,

how to check internet connection is available or not ?

i want to like CHECK internet connection is lost.
that time my windows base application popup windows "Your internet connetion is lost. "

AND my system in domain. "xyz.local"

thank you ,
Posted
Updated 7-Feb-14 2:39am
v2

To do this I have a HelloWorld HttpHandler registered on a WebServer.

This is a simple handler with a simple HelloWorld response.

I use the WebRequest object to call this handler. If I get the HelloWorld response then I'm online.
 
Share this answer
 
using System.Net.Sockets;

public Form1()
{
InitializeComponent();

//Calling method to test if connected .
Method();
}


private bool Method() //Third way, slightly slower than Method 1
{
try
{


//Tes for internet connection.
TcpClient tcpClient = new TcpClient("www.codeguru.com", 80);
//Provides client connections for TCP network services

//close if conneted.
tcpClient.Close();


//write what ever to want it to do here

//show value of connected or disconnected.
pbConnection.Value = 80;
lblLable.Text = "Connected ";

//MessageBox.Show("Connected");
return true;
}
catch (System.Exception ex)
{
//if not connected
lblLable.Text = "Disconnected";
return false; //Not connected
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900