472,373 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

how to determine Internet connection state.

I have an aplication that will consitently be comutication with a webserver
remotly via Internet. What is the best way and most lightweight way to
constently check the conection so my app will know immediatly when
connection is lost or connection is regained?
Thanks

--
Ron Vecchi

Nov 15 '05 #1
2 5634
The simplest way I've found is to import the
InternetGetConnectedState() from the wininet.dll.

You can do this by declaring a function as such:

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int desc,
int reserved);

be sure you're using the
System.Runtime.InteropServices namespace as well.

Then you can spawn a new thread to constantly be checking the internet
state by using:

int desc = 0;
if(InternetGetConnectedState(out desc, 0 /* must be zero */))
{
// we have an internet connection
}

If you need more information you can bitwise and the value of desc
with the following enum.

public enum ConnectedStates
{
INTERNET_CONNECTION_MODEM = 1, INTERNET_CONNECTION_LAN = 2,
INTERNET_CONNECTION_PROXY = 4,
INTERNET_CONNECTION_MODEM_BUSY = 8, INTERNET_RAS_INSTALLED =
16, INTERNET_CONNECTION_OFFLINE = 32,
INTERNET_CONNECTION_CONFIGURED = 64,
}

So if you want to check if you're connected via the LAN, you could
make this check
if(code & ConnectedStates.INTERNET_CONNECTION_LAN ==
ConnectedStates.INTERNET_CONNECTION_LAN)
{
// connected via LAN
}

On Fri, 5 Dec 2003 07:45:12 -0500, "Ron Vecchi"
<rv*****@xilehdvecchi.com> wrote:
I have an aplication that will consitently be comutication with a webserver
remotly via Internet. What is the best way and most lightweight way to
constently check the conection so my app will know immediatly when
connection is lost or connection is regained?
Thanks


Nov 15 '05 #2
Thanks for the info, Helped a lot!

<om***@yahoo.com> wrote in message
news:26********************************@4ax.com...
The simplest way I've found is to import the
InternetGetConnectedState() from the wininet.dll.

You can do this by declaring a function as such:

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int desc,
int reserved);

be sure you're using the
System.Runtime.InteropServices namespace as well.

Then you can spawn a new thread to constantly be checking the internet
state by using:

int desc = 0;
if(InternetGetConnectedState(out desc, 0 /* must be zero */))
{
// we have an internet connection
}

If you need more information you can bitwise and the value of desc
with the following enum.

public enum ConnectedStates
{
INTERNET_CONNECTION_MODEM = 1, INTERNET_CONNECTION_LAN = 2,
INTERNET_CONNECTION_PROXY = 4,
INTERNET_CONNECTION_MODEM_BUSY = 8, INTERNET_RAS_INSTALLED =
16, INTERNET_CONNECTION_OFFLINE = 32,
INTERNET_CONNECTION_CONFIGURED = 64,
}

So if you want to check if you're connected via the LAN, you could
make this check
if(code & ConnectedStates.INTERNET_CONNECTION_LAN ==
ConnectedStates.INTERNET_CONNECTION_LAN)
{
// connected via LAN
}

On Fri, 5 Dec 2003 07:45:12 -0500, "Ron Vecchi"
<rv*****@xilehdvecchi.com> wrote:
I have an aplication that will consitently be comutication with a webserverremotly via Internet. What is the best way and most lightweight way to
constently check the conection so my app will know immediatly when
connection is lost or connection is regained?
Thanks

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Adam Parkin | last post by:
Hello all, I need to be able to detect if there is an active available Internet connection in my VB6 program. In my program I'm using the Internet Transfer Control to transfer some files by HTTP,...
12
by: Cliff Wells | last post by:
Hi, I'm writing an application that needs to know if an Internet connection is available. Basically, I want to have something similar to what a lot of email clients have, where the app can work...
3
by: Jonny | last post by:
Hi, Please could you tell me how to check for an internet connection in C. I'm using Windows 2000. Many Thanks, Jonny
1
by: D. Wichert | last post by:
Hi folks, I use a TcpClient object to connect to a local (asynchron) socket server. Once the connection is established, I ask every second if there is a new entry in the socket queue. If the...
8
by: Steven Van Dyke | last post by:
Hi I need a code snippet to determine if my computer is connected to a network or not. There's probably a System.Net function for it, but I cannot find it. Thanks, Steve
1
by: Rubbrecht Philippe | last post by:
Hi there, I developed an application that reeds configuration settings from a central database. Whenever the dataset is read, it's also saved as a local XML file on the machine. Whenever the...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
6
by: semedao | last post by:
Hi, I have problem to determine that I don't have any internet connection when I have Lan Nic available that is connected to other computer and not to the internet. I am using the...
1
by: ricolee99 | last post by:
Hi Everyone, Thanks for reading my post. Can someone please tell me if there's something in .net framework that will allow me to determine the name of the default internet connection? I have...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.