Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to detect internet connection?

2 views
Skip to first unread message

Chris Liang

unread,
Feb 25, 2002, 8:02:18 PM2/25/02
to
Does anybody know how to detect the availability of the web server for web
service. I have an WinForm application which uses a few web service. There
are a few possible cases such as the web server is shut down or the network
to the web server is out of work. I don't know how to detect the the
connection to the web server.

Thanks


Raymond Fink

unread,
Feb 26, 2002, 1:06:50 PM2/26/02
to
A brute force approach is try the connect, and catch WebExceptions, e.g.

bool connectionOK;
try
{
// call a simple service on the Web Server that returns bool true
connectionOK = myWebService.AreYouThere();
}
catch (WebException exc)
{
MessageBox.Show(exc.Message, "Connection Failed");
connectionOK = false;
}

No doubt there are more elegant solutions...

-- Ray

In article <ufMVPjkvBHA.2500@tkmsftngp03>, "Chris Liang" <quan...@yahoo.com>
wrote:

Duke

unread,
Feb 26, 2002, 5:53:18 PM2/26/02
to

I actually do something like this:

Private Function IsAlive() As Boolean
' Initialize the WebRequest.
Try
Dim myRequest As WebRequest = WebRequest.Create
(GetConfigValue("ESBaseURL"))'//URL for web service asmx
file
Dim x As System.IO.Stream
' Return the response.
Dim myResponse As WebResponse =
myRequest.GetResponse()

' Code to use the WebResponse goes here.
' Close the response to free resources.
x = myResponse.GetResponseStream()

myResponse.Close()
Return (True)
Catch exc As Exception
MessageBox.Show("Eunexus is currently down.
Please check www.eunexusgame.com for the latest updates on
downtime. We apologize for the inconvenience.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
Return (False)
End Try
End Function

>.
>

Doug Wheeler

unread,
Feb 26, 2002, 6:27:22 PM2/26/02
to
"Chris Liang" <lia...@plural.com> wrote in message
news:ufMVPjkvBHA.2500@tkmsftngp03...

The problem with all of the replies/suggestions posted here is that they
will cause a dial-up connection (or dial-up router like the Intel Anypoint)
to dial in order to fulfill the request. It will also cause problems with
dial-up internet connection sharing (the "server" system will dial whenever
one of the client systems does any of these types of calls).

The ONLY way to do this without causing such devices to dial is to use ICMP
(a.k.a. ping) to an absolute IP address on the 'net. You can't use a name
since that requires a DNS lookup which will cause an dial. Likewise, any TCP
or UDP packet will also cause a dial.

--Doug

0 new messages