bool IsConnected
{
get
{
int flags = 0;
return InternetGetConnectedStateEx(out flags, 0, 0, 0);
}
}
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedStateEx(out int
flags, int reservedValue, int dwNameLen, int dwReserved);
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Rob S wrote:
> Hi there,
>
> I can connect to the gprs connection using:
>
> System.Net.WebRequest oReq =
> System.Net.WebRequest.Create("http://www.microsoft.com");
> WebResponse respon = oReq.GetResponse();
> respon.Close();
>
> How might i detect whether it's connected or not?
>
> before i use any socket code i would ideally call a function that returns
> true or false depending on the connection status.
>
> Can't just set a class level variable as the user may have disconnected the
> gprs manually so i need to test it there and then.
>
> any advice would be great.
>
> Thank you
Any ideas why that might happen?
I use this method together with some modification (but the main idea
remains the same) in my application and it works fine.
We use PocketPC 2003 and the Qtek 2020.
Setup a very simple smart device application in C#.
One button on it that connects to the gprs by calling up by using a web
request, that works fine.
One button that runs your code.
The user may also have a PC Connection and it should still return true for
that.
If i completely take out my gprs connection and take it out the cradle it
still returns true.
bool IsConnected
{
get
{
try
{
string hostName = Dns.GetHostName();
IPHostEntry curHost = Dns.GetHostByName(hostName);
return curHost.AddressList[0].ToString() !=
IPAddress.Loopback.ToString();
}
catch
{
return false;