检查互联网连接是否有效? [英] Check internet connection is active or not ?

查看:98
本文介绍了检查互联网连接是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



如何检查互联网连接是否可用?



i想要喜欢检查互联网连接是否丢失。

那时我的Windows基础应用程序弹出窗口你的互联网连接丢失了。



和我的域名系统。 xyz.local



谢谢你,

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 ,

推荐答案

http://stackoverflow.com/questions/2031824/what-is-the -best-way-to-for-internet-connectivity-using-net [ ^ ]

http://stackoverflow.com/questions/20309158/c-sharp-checking-internet-connection [ ^ ]


为此,我在WebServer上注册了一个HelloWorld HttpHandler



这是一个简单的处理程序HelloWorld res ponse。



我使用 WebRequest 对象来调用此处理程序。如果我收到HelloWorld响应,那么我在线。
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.


使用System.Net.Sockets;



public Form1()

{

InitializeComponent();



//调用方法来测试是否已连接。

方法();

}





private bool方法()//第三路,比方法1慢一点

{

试试

{





//用于互联网连接的Tes。

TcpClient tcpClient = new TcpClient(www.codeguru.com,80);

//为TCP网络服务提供客户端连接



//如果连接则关闭。

tcpClient.Close ();





//写下你想要它做什么



//显示已连接或已断开连接的值。

pbConnection.Value = 80;

lblLable.Text =已连接;



//MessageBox.Show(\"Connected);

返回true;

}

catch( System.Exception ex)

{

//如果没有连接

lblLable.Text =断开连接;

返回false; //未连接

}

}
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
}
}


这篇关于检查互联网连接是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆