0

我编写了简单的网络浏览器代码,我想在连接不可用时显示消息。我使用了“try catch”但它不起作用。我如何检测我的网络连接是否可用。

4

1 回答 1

0

ping 一个几乎启动的 DNS 像 4.2.2.4,4.2.2.3,4.2.2.2

Ping myPing = new Ping();
String host = "4.2.2.4;
byte[] buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success {
  // presumably online
}
于 2013-07-05T15:46:52.763 回答