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

Re: Is gprs connected?

5 views
Skip to first unread message

Sergey Bogdanov

unread,
May 11, 2005, 9:00:26 AM5/11/05
to
To detect connection state try this:

bool IsConnected
{
get
{
int flags = 0;
return InternetGetConnectedStateEx(ou­t 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

Rob S

unread,
May 11, 2005, 9:41:05 AM5/11/05
to
Hi, thanks for the response, however, it returns true whether it's connected
or not.

Any ideas why that might happen?

Sergey Bogdanov

unread,
May 11, 2005, 9:52:41 AM5/11/05
to
Please, provide more information:- How do you test it? What environment
do you have? What was the type of connection?

I use this method together with some modification (but the main idea
remains the same) in my application and it works fine.

Rob S

unread,
May 11, 2005, 10:04:10 AM5/11/05
to
Sergey,

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.

Sergey Bogdanov

unread,
May 11, 2005, 10:33:19 AM5/11/05
to
For the PPC family I would suggest you this method:

bool IsConnected
{
get
{
try
{
string hostName = Dns.GetHostName();
IPHostEntry curHost = Dns.GetHostByName(hostName);
return curHost.AddressList[0].ToString() !=
IPAddress.Loopback.ToString();
}
catch
{
return false;

Rob S

unread,
May 11, 2005, 10:50:06 AM5/11/05
to
Thanks Sergey, that works very nicely!
0 new messages