C# 클래스 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.
파일 보기 프로젝트 열기: Revelations/BaconApp

공개 메소드들

메소드 설명
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.

비공개 메소드들

메소드 설명
InternetGetConnectedState ( int &connDescription, int reservedValue ) : bool

메소드 상세

Check() 공개 정적인 메소드

public static Check ( Method method, string address, int port ) : bool
method Method
address string
port int
리턴 bool

Check() 공개 정적인 메소드

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
리턴 bool

DnsTest() 공개 정적인 메소드

public static DnsTest ( string url = DefaultHost ) : bool
url string
리턴 bool

IsConnectionAvailable() 공개 정적인 메소드

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
리턴 bool

PingTest() 공개 정적인 메소드

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
리턴 bool

TcpSocketTest() 공개 정적인 메소드

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
리턴 bool

WebRequestTest() 공개 정적인 메소드

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.
리턴 bool