detecting network connection

  • Thread starter Thread starter Brent Burkart
  • Start date Start date
B

Brent Burkart

I have a utility that I want to only run when a network connection is
present.

I want to plan for the situation when
someone unplugs their laptop from the network and takes it into another
room. My process requires a connection and I don't want it to blow up when
one does not exist.

I have tried using the "wininet.dll" API, but it still tells me I am
connected when I am unplugged from the network. Has anyone else had the
probelm or do you know of another solution.

Thanks,
Brent.
 
Brent Burkart said:
I have a utility that I want to only run when a network connection
is present.

I want to plan for the situation when
someone unplugs their laptop from the network and takes it into
another room. My process requires a connection and I don't want it
to blow up when one does not exist.

I have tried using the "wininet.dll" API, but it still tells me I
am connected when I am unplugged from the network. Has anyone else
had the probelm or do you know of another solution.

It is (very) hard (maybe even impossible) to find out if there's a network
connection. There can be several layers a connection is built upon. You
would have to check each single layer to find it out.

I think the only way to find it out is by trying to connect or to exchange
data. If it doesn't work, after a certain time-out, you know that there is
no working connection.

If your application crashes when there is no connection, you should add the
necessary exception handling.
 
Brent, I'm actively trying to find the same answer. I've used the API call
and I get the same results you do, which is disappointing. I've tried
firing http requests, but that often hangs up my machine.

Right now I'm trying to implement this
http://www.csharphelp.com/archives/archive6.html which is a Ping tool. If I
can ping the server, all is good.

I should have everything done in an hour or so, and I'll post back when I
get it done.

Cheers,

Bill
 
Back
Top