C# Class Common.ConnectStatus

Some of the functions of our applications may require a run-time test of internet connectivity. Once internet connectivity is detected, the functions that require internet access may temporarily be disabled and/or the user can be notified via an alert message. Otherwise, the application may result in error during operation or it may cause annoying problems for the user.
Afficher le fichier Open project: Revelations/BaconApp

Méthodes publiques

Méthode Description
Check ( Method method, string address, int port ) : bool
Check ( Method method = DefaultMethod, string host = DefaultHost, string ipv4 = DefaultIpAddress, int port = DefaultPort, int timeout = DefaultTimeout ) : bool

Checks whether there is an internet connection. Defaults to calling the IsConnectionAvailable method.

DnsTest ( string url = DefaultHost ) : bool

IsConnectionAvailable ( ) : bool

Check if a connection to the Internet can be established. Much faster than the other methods, as it does not require a DNS lookup.

PingTest ( string address = DefaultIpAddress, int timeout = DefaultTimeout ) : bool

Ping an IP address.

There can be some delay in response of web request, therefore this method may not be fast enough for some applications. A better way is to check whether port 80, default port for http traffic, of an always online website. You cannot use this method in .NET Compact Framework because there is no System.Net.NetworkInformation namespace that comes with Compact Framework. However, you can use Smart Device Framework ("http://www.opennetcf.com", Community Edition is free for download) provided by OpenNETCF. This framework comes with many other useful tools that .NET Compact Framework does not contain. Notice that I used Google’s IP address 208.69.34.231. We could use Google’s web address www.google.com: System.Net.NetworkInformation.PingReply pingStatus = ping.Send("www.google.com",1000); However, that will require DNS lookup which causes extra delay.

TcpSocketTest ( string address = DefaultHost, int port = DefaultPort ) : bool

There can be some delay in response of web request therefore this method may not be fast enough for some applications. A better way is to check whether port 80, default port for HTTP traffic, of an always online website.

WebRequestTest ( string address = DefaultHost ) : bool

We may send a web request to a website which assumed to be online always, for example google.com. If we can get a response, then obviously the device that runs our application is connected to the internet.

Private Methods

Méthode Description
InternetGetConnectedState ( int &connDescription, int reservedValue ) : bool

Method Details

Check() public static méthode

public static Check ( Method method, string address, int port ) : bool
method Method
address string
port int
Résultat bool

Check() public static méthode

Checks whether there is an internet connection. Defaults to calling the IsConnectionAvailable method.
public static Check ( Method method = DefaultMethod, string host = DefaultHost, string ipv4 = DefaultIpAddress, int port = DefaultPort, int timeout = DefaultTimeout ) : bool
method Method
host string
ipv4 string
port int
timeout int
Résultat bool

DnsTest() public static méthode

public static DnsTest ( string url = DefaultHost ) : bool
url string
Résultat bool

IsConnectionAvailable() public static méthode

Check if a connection to the Internet can be established. Much faster than the other methods, as it does not require a DNS lookup.
public static IsConnectionAvailable ( ) : bool
Résultat bool

PingTest() public static méthode

Ping an IP address.
There can be some delay in response of web request, therefore this method may not be fast enough for some applications. A better way is to check whether port 80, default port for http traffic, of an always online website. You cannot use this method in .NET Compact Framework because there is no System.Net.NetworkInformation namespace that comes with Compact Framework. However, you can use Smart Device Framework ("http://www.opennetcf.com", Community Edition is free for download) provided by OpenNETCF. This framework comes with many other useful tools that .NET Compact Framework does not contain. Notice that I used Google’s IP address 208.69.34.231. We could use Google’s web address www.google.com: System.Net.NetworkInformation.PingReply pingStatus = ping.Send("www.google.com",1000); However, that will require DNS lookup which causes extra delay.
public static PingTest ( string address = DefaultIpAddress, int timeout = DefaultTimeout ) : bool
address string
timeout int
Résultat bool

TcpSocketTest() public static méthode

There can be some delay in response of web request therefore this method may not be fast enough for some applications. A better way is to check whether port 80, default port for HTTP traffic, of an always online website.
public static TcpSocketTest ( string address = DefaultHost, int port = DefaultPort ) : bool
address string The address to try to connect to. Defaults to .
port int The port to use. Defaults to
Résultat bool

WebRequestTest() public static méthode

We may send a web request to a website which assumed to be online always, for example google.com. If we can get a response, then obviously the device that runs our application is connected to the internet.
public static WebRequestTest ( string address = DefaultHost ) : bool
address string The address to try to connect to. Defaults to Google.
Résultat bool