Auto reconnect to a WiFi connection

G

Guest

I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is connected live
to a SQLServer 2000 and when i get a broken connection, It shoud display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get to the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with WEP KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0 with latest
service pack.

When i start Internet explorer, it automaticaly connect one of my prefered
access point! I also notice that where i am doing test there is a lot of not
configured device (and should hide the connect to a new network wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on the network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does not exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get connected.. ;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation. (same as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes out of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe out all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL* my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol = OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue where to
look anymore!
 
P

Paul G. Tobey [eMVP]

The WEP key is set on a per-network basis. That code should not clear
settings for other SSID values. If you have two access points with the same
SSID, then, yes, changing the WEP key for either will affect the other
because Windows CE doesn't distinguish between APs with the same SSID
(they're the same network, as far as it's concerned). Maybe that's the
problem here. *Do* they have different SSIDs? If so and if you use the WZC
settings to configure the connections, they *will* automatically reconnect
after a time set by Windows CE. I don't think that you're going to do much
better, usability, than just letting CE do it's thing and, if you get a
server-not-found error, do the right thing in your application.

Paul T.

Vincent said:
I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is connected
live
to a SQLServer 2000 and when i get a broken connection, It shoud display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get to the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with WEP
KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0 with
latest
service pack.

When i start Internet explorer, it automaticaly connect one of my prefered
access point! I also notice that where i am doing test there is a lot of
not
configured device (and should hide the connect to a new network wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on the
network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does not
exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get connected.. ;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation. (same as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes out of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe out
all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL* my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP
configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue where to
look anymore!
 
G

Guest

My access point get all differents SSID values

You are talking of my Fourth setup?
OpenNetCF use WZCQueryInterface and WZCSetInterface u can get a look to the
code at
http://vault.netcf.tv/VaultService/...spx?File=2$/SDF/v1.4/OpenNETCF.Net/Adapter.cs
(using login guest, guest)

But when i look to the code it seem that buff all the entries and set them
back (or flushing it) when calling WZCSetInterface. That should explain why
my setting are resetted.
The only remaining configured AP is the one i used when calling
SetWirelessSettings ;o(

I cant go deeper in the code, wasn't able to get more documentation on the
api call, and
maybe missing some skill ;o)

Anybody know annother wrapper for theese call?
Or another way to solve my problems?
Thanks...

Paul G. Tobey said:
The WEP key is set on a per-network basis. That code should not clear
settings for other SSID values. If you have two access points with the same
SSID, then, yes, changing the WEP key for either will affect the other
because Windows CE doesn't distinguish between APs with the same SSID
(they're the same network, as far as it's concerned). Maybe that's the
problem here. *Do* they have different SSIDs? If so and if you use the WZC
settings to configure the connections, they *will* automatically reconnect
after a time set by Windows CE. I don't think that you're going to do much
better, usability, than just letting CE do it's thing and, if you get a
server-not-found error, do the right thing in your application.

Paul T.

Vincent said:
I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is connected
live
to a SQLServer 2000 and when i get a broken connection, It shoud display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get to the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with WEP
KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0 with
latest
service pack.

When i start Internet explorer, it automaticaly connect one of my prefered
access point! I also notice that where i am doing test there is a lot of
not
configured device (and should hide the connect to a new network wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on the
network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does not
exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get connected.. ;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation. (same as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes out of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe out
all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL* my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP
configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue where to
look anymore!
 
P

Paul G. Tobey [eMVP]

There is no documentation for SetWirelessSettings(), and yes, I'm talking
about the WZC calls.

It does remove the other APs from the preferred list. Sorry about that. At
some point, that will be fixed. For now, if you aren't concerned about
that, you can simply force the connection to the SSID value that you want.

I've also fixed a couple of minor bugs in the OpenNETCF.Net namespace. Make
sure you're using the latest...

Paul T.

Vincent said:
My access point get all differents SSID values

You are talking of my Fourth setup?
OpenNetCF use WZCQueryInterface and WZCSetInterface u can get a look to
the
code at
http://vault.netcf.tv/VaultService/...spx?File=2$/SDF/v1.4/OpenNETCF.Net/Adapter.cs
(using login guest, guest)

But when i look to the code it seem that buff all the entries and set them
back (or flushing it) when calling WZCSetInterface. That should explain
why
my setting are resetted.
The only remaining configured AP is the one i used when calling
SetWirelessSettings ;o(

I cant go deeper in the code, wasn't able to get more documentation on the
api call, and
maybe missing some skill ;o)

Anybody know annother wrapper for theese call?
Or another way to solve my problems?
Thanks...

Paul G. Tobey said:
The WEP key is set on a per-network basis. That code should not clear
settings for other SSID values. If you have two access points with the
same
SSID, then, yes, changing the WEP key for either will affect the other
because Windows CE doesn't distinguish between APs with the same SSID
(they're the same network, as far as it's concerned). Maybe that's the
problem here. *Do* they have different SSIDs? If so and if you use the
WZC
settings to configure the connections, they *will* automatically
reconnect
after a time set by Windows CE. I don't think that you're going to do
much
better, usability, than just letting CE do it's thing and, if you get a
server-not-found error, do the right thing in your application.

Paul T.

Vincent said:
I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is connected
live
to a SQLServer 2000 and when i get a broken connection, It shoud
display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the
network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get to
the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with
WEP
KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0 with
latest
service pack.

When i start Internet explorer, it automaticaly connect one of my
prefered
access point! I also notice that where i am doing test there is a lot
of
not
configured device (and should hide the connect to a new network wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on the
network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does not
exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get connected..
;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation. (same
as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes out
of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my
acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe
out
all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL* my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP
configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue where
to
look anymore!
 
G

Guest

Thanks for the fix in AccessPointCollection.cs... I'll check to get an entire
getlatest... later this week...

Hum.. I think that I wont get a valuable and final solution for now...
we cant affort reseting wep key of prefered device... at least should be
fixable in 2-3 months!

1- "At some point, that will be fixed." have you an idea of time?
Can i do anything to help that? Maybe could do some testing or anythings
else...

2- Is there will be a possibility to call SetWirelessSettings without
specifying
the WEP key and using the one alrealy configured?

3- Is SetWirelessSettings will work with WAP key?

Depending of your answer I may plan to write a configuration file
of device / wep key... and list them to the user... without using
PreferredAccessPoints (useless because will be flushed...)
and use SetWirelessSetting... could be a solution for my short deadline...
but I will need to issue that!

Thants a lot for your helps!
Vincent

Paul G. Tobey said:
There is no documentation for SetWirelessSettings(), and yes, I'm talking
about the WZC calls.

It does remove the other APs from the preferred list. Sorry about that. At
some point, that will be fixed. For now, if you aren't concerned about
that, you can simply force the connection to the SSID value that you want.

I've also fixed a couple of minor bugs in the OpenNETCF.Net namespace. Make
sure you're using the latest...

Paul T.

Vincent said:
My access point get all differents SSID values

You are talking of my Fourth setup?
OpenNetCF use WZCQueryInterface and WZCSetInterface u can get a look to
the
code at
http://vault.netcf.tv/VaultService/...spx?File=2$/SDF/v1.4/OpenNETCF.Net/Adapter.cs
(using login guest, guest)

But when i look to the code it seem that buff all the entries and set them
back (or flushing it) when calling WZCSetInterface. That should explain
why
my setting are resetted.
The only remaining configured AP is the one i used when calling
SetWirelessSettings ;o(

I cant go deeper in the code, wasn't able to get more documentation on the
api call, and
maybe missing some skill ;o)

Anybody know annother wrapper for theese call?
Or another way to solve my problems?
Thanks...

Paul G. Tobey said:
The WEP key is set on a per-network basis. That code should not clear
settings for other SSID values. If you have two access points with the
same
SSID, then, yes, changing the WEP key for either will affect the other
because Windows CE doesn't distinguish between APs with the same SSID
(they're the same network, as far as it's concerned). Maybe that's the
problem here. *Do* they have different SSIDs? If so and if you use the
WZC
settings to configure the connections, they *will* automatically
reconnect
after a time set by Windows CE. I don't think that you're going to do
much
better, usability, than just letting CE do it's thing and, if you get a
server-not-found error, do the right thing in your application.

Paul T.

I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is connected
live
to a SQLServer 2000 and when i get a broken connection, It shoud
display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the
network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get to
the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with
WEP
KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0 with
latest
service pack.

When i start Internet explorer, it automaticaly connect one of my
prefered
access point! I also notice that where i am doing test there is a lot
of
not
configured device (and should hide the connect to a new network wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on the
network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does not
exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get connected..
;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation. (same
as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes out
of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my
acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe
out
all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL* my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP
configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue where
to
look anymore!
 
P

Paul G. Tobey [eMVP]

It doesn't reset any keys, just changes the preferred list, as far as I can
tell. Isn't the only way that any reconnection is made via your program? I
think that your short-term idea is probably the best and probably matches
what the WZC code actually does internally.

1. When my job allows, I'll get to it. I don't know how big a job it is,
either, so I can't really predict...

2. I don't know off-hand. Again, this call is undocumented. You can try it
yourself by copying the various P/Invoke declarations to your own code and
just calling it. My guess is no, however.

3. Not the way the code is currently set up and I have no means to test it
here, so...

Paul T.

Vincent said:
Thanks for the fix in AccessPointCollection.cs... I'll check to get an
entire
getlatest... later this week...

Hum.. I think that I wont get a valuable and final solution for now...
we cant affort reseting wep key of prefered device... at least should be
fixable in 2-3 months!

1- "At some point, that will be fixed." have you an idea of time?
Can i do anything to help that? Maybe could do some testing or anythings
else...

2- Is there will be a possibility to call SetWirelessSettings without
specifying
the WEP key and using the one alrealy configured?

3- Is SetWirelessSettings will work with WAP key?

Depending of your answer I may plan to write a configuration file
of device / wep key... and list them to the user... without using
PreferredAccessPoints (useless because will be flushed...)
and use SetWirelessSetting... could be a solution for my short deadline...
but I will need to issue that!

Thants a lot for your helps!
Vincent

Paul G. Tobey said:
There is no documentation for SetWirelessSettings(), and yes, I'm talking
about the WZC calls.

It does remove the other APs from the preferred list. Sorry about that.
At
some point, that will be fixed. For now, if you aren't concerned about
that, you can simply force the connection to the SSID value that you
want.

I've also fixed a couple of minor bugs in the OpenNETCF.Net namespace.
Make
sure you're using the latest...

Paul T.

Vincent said:
My access point get all differents SSID values

You are talking of my Fourth setup?
OpenNetCF use WZCQueryInterface and WZCSetInterface u can get a look
to
the
code at
http://vault.netcf.tv/VaultService/...spx?File=2$/SDF/v1.4/OpenNETCF.Net/Adapter.cs
(using login guest, guest)

But when i look to the code it seem that buff all the entries and set
them
back (or flushing it) when calling WZCSetInterface. That should explain
why
my setting are resetted.
The only remaining configured AP is the one i used when calling
SetWirelessSettings ;o(

I cant go deeper in the code, wasn't able to get more documentation on
the
api call, and
maybe missing some skill ;o)

Anybody know annother wrapper for theese call?
Or another way to solve my problems?
Thanks...

:

The WEP key is set on a per-network basis. That code should not clear
settings for other SSID values. If you have two access points with
the
same
SSID, then, yes, changing the WEP key for either will affect the other
because Windows CE doesn't distinguish between APs with the same SSID
(they're the same network, as far as it's concerned). Maybe that's
the
problem here. *Do* they have different SSIDs? If so and if you use
the
WZC
settings to configure the connections, they *will* automatically
reconnect
after a time set by Windows CE. I don't think that you're going to do
much
better, usability, than just letting CE do it's thing and, if you get
a
server-not-found error, do the right thing in your application.

Paul T.

I need to make an application (on a Pocket PC 2003) that automaticaly
reconnect when a connection is available. The application is
connected
live
to a SQLServer 2000 and when i get a broken connection, It shoud
display a
message to the user
"Network connection lost, Reconnect?" Ok = Try to connect to the
network
(available configured AccessPoint) an perform operation
Cancel = discard operation an wait until user try again
(the message will loop until success or cancel)

The application is destinated to verry novice user and
should be the most transparent as possible... down want them to get
to
the
device settings...

I'have tryed many things and nothings seem to work!
What i'm doing wrong... is it my device?
Is i understand something wrong?

The pocket PC is a DELL AXIM
2 Wifi acces point (MYACCESSPOINT no WEP KEY and MYACCESSPOINT2 with
WEP
KEY)
developping in C# using Visual Studio 2003 Compact Framework 1.0
with
latest
service pack.

When i start Internet explorer, it automaticaly connect one of my
prefered
access point! I also notice that where i am doing test there is a
lot
of
not
configured device (and should hide the connect to a new network
wizard)


== First setup: ==

I configure both as prefered devices and connect to one acces point

- I write a simple apps that open a connection on a SQL server on
the
network
- I goes out of scope the two acces point
- I came back near the acces point and wait... (1 minute and more)
- Try to re open the connection an get an error like "server does
not
exists"


== Second setup: ==

I read a bit an try the fallowing (with OpenNETCF),
after the error "server does not exists" i call my function
TakeConnection() but the code never break... so never get
connected..
;o(

private void TakeConnection()
{
ConnectionManager oCon = new ConnectionManager();
foreach( DestinationInfo d in oInfo )
{
bool connected = false;
if(d.description == "work")
{
oCon.Connect(d.guid, true, ConnectionMode.Asynchronous);
while(!connected)
{
if(_oCon.Status != ConnectionStatus.Connected)
{
System.Threading.Thread.Sleep(1000);
continue;
}
connected = true;
}
}
}
}


== Third setup: ==

I keept a member instance of ConnectionManager
and call a function like DoConnection at the form initialisation.
(same
as
TakeConnection with the global member)
The function also register to events OnConnect, OnDisconnect,
OnConnectionFailed, OnConnectionStateChanged...
When i start the app, i got the OnConnect, but when connection goes
out
of
my access point, never got disconnected or anythings else...
also never get reconnected when the AP becone available.


== Fourth setup: ==

I tryed SetWirelessSettings to force the reconnection to one of my
acces
point, it work fine except that
the way the function seems to be impelemeted (in OpenNETCF 1.4) wipe
out
all
my prefered device and their
configuration. When i call the fallowing code, the wep key of *ALL*
my
prefered access point are gone...
(MYACCESSPOINT doesn't get wep key but MYACCESPOINT2 does)

OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.SetWirelessSettings("MYACCESSPOINT", true, (byte[])null);
a.RebindAdapter();
}
}

if I could fix theese two issue, this could be a nice solution:
- Retreive a way to get the wep key of the AP configured in the
deveice
(settings)
- Find a way to SetWirelessSettings without mixed up all the AP
configuration


==Conclusion ===========
Thanks a lot for your help,
please help me to get samples or full articles helping me
to demystify that, my deadlines are really short and have no clue
where
to
look anymore!
 
G

Guest

It doesn't reset any keys, just changes the preferred list, as far as I can
tell. Isn't the only way that any reconnection is made via your program?

1- It's the only way i try the connection... in the post you will find two
function that i call from a simple test main form with two button and a
textbox...
nothing else... all my setup is discribed here.

2- I can tell you that on my device, it's all gone... wep key disapear!
I should be able to borrow other Pocket PC device tomorrow.. and will try my
test again!

Let’s explain my test...
We own 3 access point configured as fallow:
INTERALAP -> secured with a WEP key (prefered on my pocket and able to query
to database)
TORENADODMZ -> not secured (prefered on my pocket and able to query to
database)
TORENADO -> used by laptop and secured with a WAP key (cant use it since my
PocketPC doesn't support wap)


- I manally connect to INTERALAP (from setting pannel)
- I call ConnectToSQL() and get my sql results form INTERALAP
- I call SetTorenadoDMZ()
- I call ConnectToSQL() and get my sql results now from TorenadoDMZ
- I manually connect to INTERALAP (and saw a lock icon with a X red in my
status bar)
- I call ConnectToSQL() and get SQL server does not exist or access denied!
- go to the setting an reenter my wep key
- I call ConnectToSQL() and get my sql results form INTERALAP



private void SetTorenadoDMZ()
{
OpenNETCF.Net.AdapterCollection oCol = OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
string sValue = Convert.ToString(listBox1.SelectedItem);
a.SetWirelessSettings("TORENADODMZ", true, (byte[])null);
return;
}
}
}

private void ConnectToSQL()
{
txtConn.Text = "Try to connect to sql...";
string sConnectString = "user id=sa;password=MYPWD;initial
catalog=INTERAL_DEV;data source=10.0.0.30;Connect Timeout=10";
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
SqlCommand oComm = con.CreateCommand();
oComm.CommandText = "SELECT * from EMPL_EMPLOYEE";
oComm.CommandType = CommandType.Text;
SqlDataReader r = oComm.ExecuteReader();
while(r.Read())
{
txtConn.Text += Convert.ToString(r["NO_EMPLOYEE"]) + ", ";
}

con.Close();
}
catch(SqlException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
txtConn.Text = ex.Message;
return;
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
txtConn.Text = ex.Message;
return;
}
txtConn.Text += "\r\nDone.";
}
 
P

Paul G. Tobey [eMVP]

One other thing you might try is doing a RebindAdapter() when you think you
might be back in range and want the adapter to try to reconnect. There's no
way to know if you really are there, unless you want to check the list of
nearby APs, but rebinding *might* cause the adapter to reconnect to one of
its preferred APs...

Paul T.

Vincent said:
It doesn't reset any keys, just changes the preferred list, as far as I
can
tell. Isn't the only way that any reconnection is made via your program?

1- It's the only way i try the connection... in the post you will find two
function that i call from a simple test main form with two button and a
textbox...
nothing else... all my setup is discribed here.

2- I can tell you that on my device, it's all gone... wep key disapear!
I should be able to borrow other Pocket PC device tomorrow.. and will try
my
test again!

Let's explain my test...
We own 3 access point configured as fallow:
INTERALAP -> secured with a WEP key (prefered on my pocket and able to
query
to database)
TORENADODMZ -> not secured (prefered on my pocket and able to query to
database)
TORENADO -> used by laptop and secured with a WAP key (cant use it since
my
PocketPC doesn't support wap)


- I manally connect to INTERALAP (from setting pannel)
- I call ConnectToSQL() and get my sql results form INTERALAP
- I call SetTorenadoDMZ()
- I call ConnectToSQL() and get my sql results now from TorenadoDMZ
- I manually connect to INTERALAP (and saw a lock icon with a X red in my
status bar)
- I call ConnectToSQL() and get SQL server does not exist or access
denied!
- go to the setting an reenter my wep key
- I call ConnectToSQL() and get my sql results form INTERALAP



private void SetTorenadoDMZ()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
string sValue = Convert.ToString(listBox1.SelectedItem);
a.SetWirelessSettings("TORENADODMZ", true, (byte[])null);
return;
}
}
}

private void ConnectToSQL()
{
txtConn.Text = "Try to connect to sql...";
string sConnectString = "user id=sa;password=MYPWD;initial
catalog=INTERAL_DEV;data source=10.0.0.30;Connect Timeout=10";
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
SqlCommand oComm = con.CreateCommand();
oComm.CommandText = "SELECT * from EMPL_EMPLOYEE";
oComm.CommandType = CommandType.Text;
SqlDataReader r = oComm.ExecuteReader();
while(r.Read())
{
txtConn.Text += Convert.ToString(r["NO_EMPLOYEE"]) + ", ";
}

con.Close();
}
catch(SqlException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
txtConn.Text = ex.Message;
return;
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
txtConn.Text = ex.Message;
return;
}
txtConn.Text += "\r\nDone.";
}




Paul G. Tobey said:
It doesn't reset any keys, just changes the preferred list, as far as I
can
tell. Isn't the only way that any reconnection is made via your program?
I
think that your short-term idea is probably the best and probably matches
what the WZC code actually does internally.

1. When my job allows, I'll get to it. I don't know how big a job it is,
either, so I can't really predict...

2. I don't know off-hand. Again, this call is undocumented. You can try
it
yourself by copying the various P/Invoke declarations to your own code
and
just calling it. My guess is no, however.

3. Not the way the code is currently set up and I have no means to test
it
here, so...

Paul T.
 
G

Guest

You rock, RebindAdapter is a valuable solution... never think to try it
without modifying params ;o)

Here will be my senario, I posted it to help others... in my project
SimpleText will be will be implemented in a modal form with a timer
and a Cancel button. as soon as a satisfying connection is made
the dialog will close, if the user cancel a "UserCanceledException" will be
trowed.

When writing ConnectedToNetwork, my first approch was to use a Ping to
verify whatever the sqlserver is available (on non prefered network) but
when using USB the IP assigned to me doesn't match te subnet and I dont
really know why but IsSQLServerAvailable work and get connected ... so that's
find for my purpose!

The only issue here is if we got a prefered AP that can't reach sql server
but this can't be fixed without being able to force connecting on a specific
device.. *maybe* later... that's really satisfying for now. and we should
never got on that issue because logicaly both shouldn't be nearby ;o)

** I will also suggest to configure the device to "auto connect on non
prefered device" this way user wont have a popup up bubble asking if they
want to connect on a new discovered network...

Thanks a lot for your help, if you get furter in SetWirelessSetting
or need help to test you can notify me at (e-mail address removed)

private void SimpleTest()
{
while( !ConnectedToNetwork() )
{
//Try to rebind the wireless should be ok next time
if( IsNearbyPrefered() )
RebindWireless(); //Please wait a few seconds before checking again

System.Threading.Thread.Sleep(3000);
}

//Retreive data from sql server
ConnectToSQL(K_CONNECT_STRING);
}

private bool ConnectedToNetwork()
{
if( IsIpAssigned() ) //Device alrealy connected somewhere (get a IP)
{
//Connected on a prefered device
//(the only issue here is if we got a prefered device that cant reach sql
server, but cant really fix it
//without being able to force connecting on a specific device.. maybe
later...)
if( IsConnectedOnPrefered() )
return true;

//Server still reachable even if not on prefered AP (ex USB connection or
....)
if( IsSQLServerAvailable(K_CONNECT_STRING) )
return true;
}

return false;
}

public static bool IsIpAssigned()
{
try
{

string sHostName = Dns.GetHostName();
IPHostEntry host = Dns.GetHostByName(sHostName);
string sIpAddr = host.AddressList[0].ToString();
return sIpAddr != IPAddress.Parse("127.0.0.1").ToString();
}
catch
{
return false;
}
}

private void RebindWireless()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.RebindAdapter();
return;
}
}
}

private bool IsSQLServerAvailable(string sConnectString)
{
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
con.Close();
return true;
}
catch {}

return false;
}

public bool IsConnectedOnPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
if(a.AssociatedAccessPoint == null || a.AssociatedAccessPoint.Length ==
0) //Not connected on AP
return false;

AccessPointCollection oAColl = a.PreferredAccessPoints;
foreach(OpenNETCF.Net.AccessPoint access in oAColl)
{
if(access.Name == a.AssociatedAccessPoint)
return true;
}
}
}
return false;
}

private bool IsNearbyPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
AccessPointCollection oAColl = a.NearbyPreferredAccessPoints;
return oAColl.Count > 0;
}
}
return false;
}
 
P

Paul G. Tobey [eMVP]

I've added another overload of SetWirelessSettings() to Adapter. This
version, which simply takes an SSID value, simply rearranges the preferred
adapter list so that the indicated SSID is at the top. This should cause
the WZC stack to try to reconnect to that SSID, using the settings (WEP,
etc.), from the previous configuration. On my device, at least, it works
very well. I don't know what it will do if the new top-priority SSID is out
of range or something, but it does nothing if it's not in the preferred list
already...

The latest version in the Vault has this change. Two files were modifed:
Adapter.cs and AccessPointCollection.cs. This change should not affect
existing code...

Paul T.

Vincent said:
You rock, RebindAdapter is a valuable solution... never think to try it
without modifying params ;o)

Here will be my senario, I posted it to help others... in my project
SimpleText will be will be implemented in a modal form with a timer
and a Cancel button. as soon as a satisfying connection is made
the dialog will close, if the user cancel a "UserCanceledException" will
be
trowed.

When writing ConnectedToNetwork, my first approch was to use a Ping to
verify whatever the sqlserver is available (on non prefered network) but
when using USB the IP assigned to me doesn't match te subnet and I dont
really know why but IsSQLServerAvailable work and get connected ... so
that's
find for my purpose!

The only issue here is if we got a prefered AP that can't reach sql server
but this can't be fixed without being able to force connecting on a
specific
device.. *maybe* later... that's really satisfying for now. and we should
never got on that issue because logicaly both shouldn't be nearby ;o)

** I will also suggest to configure the device to "auto connect on non
prefered device" this way user wont have a popup up bubble asking if they
want to connect on a new discovered network...

Thanks a lot for your help, if you get furter in SetWirelessSetting
or need help to test you can notify me at (e-mail address removed)

private void SimpleTest()
{
while( !ConnectedToNetwork() )
{
//Try to rebind the wireless should be ok next time
if( IsNearbyPrefered() )
RebindWireless(); //Please wait a few seconds before checking again

System.Threading.Thread.Sleep(3000);
}

//Retreive data from sql server
ConnectToSQL(K_CONNECT_STRING);
}

private bool ConnectedToNetwork()
{
if( IsIpAssigned() ) //Device alrealy connected somewhere (get a IP)
{
//Connected on a prefered device
//(the only issue here is if we got a prefered device that cant reach sql
server, but cant really fix it
//without being able to force connecting on a specific device.. maybe
later...)
if( IsConnectedOnPrefered() )
return true;

//Server still reachable even if not on prefered AP (ex USB connection or
...)
if( IsSQLServerAvailable(K_CONNECT_STRING) )
return true;
}

return false;
}

public static bool IsIpAssigned()
{
try
{

string sHostName = Dns.GetHostName();
IPHostEntry host = Dns.GetHostByName(sHostName);
string sIpAddr = host.AddressList[0].ToString();
return sIpAddr != IPAddress.Parse("127.0.0.1").ToString();
}
catch
{
return false;
}
}

private void RebindWireless()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.RebindAdapter();
return;
}
}
}

private bool IsSQLServerAvailable(string sConnectString)
{
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
con.Close();
return true;
}
catch {}

return false;
}

public bool IsConnectedOnPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
if(a.AssociatedAccessPoint == null || a.AssociatedAccessPoint.Length ==
0) //Not connected on AP
return false;

AccessPointCollection oAColl = a.PreferredAccessPoints;
foreach(OpenNETCF.Net.AccessPoint access in oAColl)
{
if(access.Name == a.AssociatedAccessPoint)
return true;
}
}
}
return false;
}

private bool IsNearbyPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
AccessPointCollection oAColl = a.NearbyPreferredAccessPoints;
return oAColl.Count > 0;
}
}
return false;
}


Paul G. Tobey said:
One other thing you might try is doing a RebindAdapter() when you think
you
might be back in range and want the adapter to try to reconnect. There's
no
way to know if you really are there, unless you want to check the list of
nearby APs, but rebinding *might* cause the adapter to reconnect to one
of
its preferred APs...

Paul T.
 
G

Guest

Thanks
I'll look at it, For now the RebindWireless() seem to work well for my
case... but if i get time I will try your modification!

Paul G. Tobey said:
I've added another overload of SetWirelessSettings() to Adapter. This
version, which simply takes an SSID value, simply rearranges the preferred
adapter list so that the indicated SSID is at the top. This should cause
the WZC stack to try to reconnect to that SSID, using the settings (WEP,
etc.), from the previous configuration. On my device, at least, it works
very well. I don't know what it will do if the new top-priority SSID is out
of range or something, but it does nothing if it's not in the preferred list
already...

The latest version in the Vault has this change. Two files were modifed:
Adapter.cs and AccessPointCollection.cs. This change should not affect
existing code...

Paul T.

Vincent said:
You rock, RebindAdapter is a valuable solution... never think to try it
without modifying params ;o)

Here will be my senario, I posted it to help others... in my project
SimpleText will be will be implemented in a modal form with a timer
and a Cancel button. as soon as a satisfying connection is made
the dialog will close, if the user cancel a "UserCanceledException" will
be
trowed.

When writing ConnectedToNetwork, my first approch was to use a Ping to
verify whatever the sqlserver is available (on non prefered network) but
when using USB the IP assigned to me doesn't match te subnet and I dont
really know why but IsSQLServerAvailable work and get connected ... so
that's
find for my purpose!

The only issue here is if we got a prefered AP that can't reach sql server
but this can't be fixed without being able to force connecting on a
specific
device.. *maybe* later... that's really satisfying for now. and we should
never got on that issue because logicaly both shouldn't be nearby ;o)

** I will also suggest to configure the device to "auto connect on non
prefered device" this way user wont have a popup up bubble asking if they
want to connect on a new discovered network...

Thanks a lot for your help, if you get furter in SetWirelessSetting
or need help to test you can notify me at (e-mail address removed)

private void SimpleTest()
{
while( !ConnectedToNetwork() )
{
//Try to rebind the wireless should be ok next time
if( IsNearbyPrefered() )
RebindWireless(); //Please wait a few seconds before checking again

System.Threading.Thread.Sleep(3000);
}

//Retreive data from sql server
ConnectToSQL(K_CONNECT_STRING);
}

private bool ConnectedToNetwork()
{
if( IsIpAssigned() ) //Device alrealy connected somewhere (get a IP)
{
//Connected on a prefered device
//(the only issue here is if we got a prefered device that cant reach sql
server, but cant really fix it
//without being able to force connecting on a specific device.. maybe
later...)
if( IsConnectedOnPrefered() )
return true;

//Server still reachable even if not on prefered AP (ex USB connection or
...)
if( IsSQLServerAvailable(K_CONNECT_STRING) )
return true;
}

return false;
}

public static bool IsIpAssigned()
{
try
{

string sHostName = Dns.GetHostName();
IPHostEntry host = Dns.GetHostByName(sHostName);
string sIpAddr = host.AddressList[0].ToString();
return sIpAddr != IPAddress.Parse("127.0.0.1").ToString();
}
catch
{
return false;
}
}

private void RebindWireless()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.RebindAdapter();
return;
}
}
}

private bool IsSQLServerAvailable(string sConnectString)
{
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
con.Close();
return true;
}
catch {}

return false;
}

public bool IsConnectedOnPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
if(a.AssociatedAccessPoint == null || a.AssociatedAccessPoint.Length ==
0) //Not connected on AP
return false;

AccessPointCollection oAColl = a.PreferredAccessPoints;
foreach(OpenNETCF.Net.AccessPoint access in oAColl)
{
if(access.Name == a.AssociatedAccessPoint)
return true;
}
}
}
return false;
}

private bool IsNearbyPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
AccessPointCollection oAColl = a.NearbyPreferredAccessPoints;
return oAColl.Count > 0;
}
}
return false;
}


Paul G. Tobey said:
One other thing you might try is doing a RebindAdapter() when you think
you
might be back in range and want the adapter to try to reconnect. There's
no
way to know if you really are there, unless you want to check the list of
nearby APs, but rebinding *might* cause the adapter to reconnect to one
of
its preferred APs...

Paul T.
 
G

Guest

Hi Paul,
What is the Brand and Model of your device?
Thanks

Paul G. Tobey said:
I've added another overload of SetWirelessSettings() to Adapter. This
version, which simply takes an SSID value, simply rearranges the preferred
adapter list so that the indicated SSID is at the top. This should cause
the WZC stack to try to reconnect to that SSID, using the settings (WEP,
etc.), from the previous configuration. On my device, at least, it works
very well. I don't know what it will do if the new top-priority SSID is out
of range or something, but it does nothing if it's not in the preferred list
already...

The latest version in the Vault has this change. Two files were modifed:
Adapter.cs and AccessPointCollection.cs. This change should not affect
existing code...

Paul T.

Vincent said:
You rock, RebindAdapter is a valuable solution... never think to try it
without modifying params ;o)

Here will be my senario, I posted it to help others... in my project
SimpleText will be will be implemented in a modal form with a timer
and a Cancel button. as soon as a satisfying connection is made
the dialog will close, if the user cancel a "UserCanceledException" will
be
trowed.

When writing ConnectedToNetwork, my first approch was to use a Ping to
verify whatever the sqlserver is available (on non prefered network) but
when using USB the IP assigned to me doesn't match te subnet and I dont
really know why but IsSQLServerAvailable work and get connected ... so
that's
find for my purpose!

The only issue here is if we got a prefered AP that can't reach sql server
but this can't be fixed without being able to force connecting on a
specific
device.. *maybe* later... that's really satisfying for now. and we should
never got on that issue because logicaly both shouldn't be nearby ;o)

** I will also suggest to configure the device to "auto connect on non
prefered device" this way user wont have a popup up bubble asking if they
want to connect on a new discovered network...

Thanks a lot for your help, if you get furter in SetWirelessSetting
or need help to test you can notify me at (e-mail address removed)

private void SimpleTest()
{
while( !ConnectedToNetwork() )
{
//Try to rebind the wireless should be ok next time
if( IsNearbyPrefered() )
RebindWireless(); //Please wait a few seconds before checking again

System.Threading.Thread.Sleep(3000);
}

//Retreive data from sql server
ConnectToSQL(K_CONNECT_STRING);
}

private bool ConnectedToNetwork()
{
if( IsIpAssigned() ) //Device alrealy connected somewhere (get a IP)
{
//Connected on a prefered device
//(the only issue here is if we got a prefered device that cant reach sql
server, but cant really fix it
//without being able to force connecting on a specific device.. maybe
later...)
if( IsConnectedOnPrefered() )
return true;

//Server still reachable even if not on prefered AP (ex USB connection or
...)
if( IsSQLServerAvailable(K_CONNECT_STRING) )
return true;
}

return false;
}

public static bool IsIpAssigned()
{
try
{

string sHostName = Dns.GetHostName();
IPHostEntry host = Dns.GetHostByName(sHostName);
string sIpAddr = host.AddressList[0].ToString();
return sIpAddr != IPAddress.Parse("127.0.0.1").ToString();
}
catch
{
return false;
}
}

private void RebindWireless()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.RebindAdapter();
return;
}
}
}

private bool IsSQLServerAvailable(string sConnectString)
{
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
con.Close();
return true;
}
catch {}

return false;
}

public bool IsConnectedOnPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
if(a.AssociatedAccessPoint == null || a.AssociatedAccessPoint.Length ==
0) //Not connected on AP
return false;

AccessPointCollection oAColl = a.PreferredAccessPoints;
foreach(OpenNETCF.Net.AccessPoint access in oAColl)
{
if(access.Name == a.AssociatedAccessPoint)
return true;
}
}
}
return false;
}

private bool IsNearbyPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
AccessPointCollection oAColl = a.NearbyPreferredAccessPoints;
return oAColl.Count > 0;
}
}
return false;
}


Paul G. Tobey said:
One other thing you might try is doing a RebindAdapter() when you think
you
might be back in range and want the adapter to try to reconnect. There's
no
way to know if you really are there, unless you want to check the list of
nearby APs, but rebinding *might* cause the adapter to reconnect to one
of
its preferred APs...

Paul T.
 
P

Paul G. Tobey [eMVP]

Of the device or of the wireless card or of the access point(s)? I've
tested with our LANpoint CE.NET and LANpoint Plus and with Cisco 352 and
Prism2.5-based PCMCIA cards and with a Cisco 1200 series access point and a
LinkSys AP.

Is there a real question in there?

Paul T.

B. Ron F. said:
Hi Paul,
What is the Brand and Model of your device?
Thanks

Paul G. Tobey said:
I've added another overload of SetWirelessSettings() to Adapter. This
version, which simply takes an SSID value, simply rearranges the
preferred
adapter list so that the indicated SSID is at the top. This should cause
the WZC stack to try to reconnect to that SSID, using the settings (WEP,
etc.), from the previous configuration. On my device, at least, it works
very well. I don't know what it will do if the new top-priority SSID is
out
of range or something, but it does nothing if it's not in the preferred
list
already...

The latest version in the Vault has this change. Two files were modifed:
Adapter.cs and AccessPointCollection.cs. This change should not affect
existing code...

Paul T.

Vincent said:
You rock, RebindAdapter is a valuable solution... never think to try it
without modifying params ;o)

Here will be my senario, I posted it to help others... in my project
SimpleText will be will be implemented in a modal form with a timer
and a Cancel button. as soon as a satisfying connection is made
the dialog will close, if the user cancel a "UserCanceledException"
will
be
trowed.

When writing ConnectedToNetwork, my first approch was to use a Ping to
verify whatever the sqlserver is available (on non prefered network)
but
when using USB the IP assigned to me doesn't match te subnet and I dont
really know why but IsSQLServerAvailable work and get connected ... so
that's
find for my purpose!

The only issue here is if we got a prefered AP that can't reach sql
server
but this can't be fixed without being able to force connecting on a
specific
device.. *maybe* later... that's really satisfying for now. and we
should
never got on that issue because logicaly both shouldn't be nearby ;o)

** I will also suggest to configure the device to "auto connect on non
prefered device" this way user wont have a popup up bubble asking if
they
want to connect on a new discovered network...

Thanks a lot for your help, if you get furter in SetWirelessSetting
or need help to test you can notify me at (e-mail address removed)

private void SimpleTest()
{
while( !ConnectedToNetwork() )
{
//Try to rebind the wireless should be ok next time
if( IsNearbyPrefered() )
RebindWireless(); //Please wait a few seconds before checking again

System.Threading.Thread.Sleep(3000);
}

//Retreive data from sql server
ConnectToSQL(K_CONNECT_STRING);
}

private bool ConnectedToNetwork()
{
if( IsIpAssigned() ) //Device alrealy connected somewhere (get a IP)
{
//Connected on a prefered device
//(the only issue here is if we got a prefered device that cant reach
sql
server, but cant really fix it
//without being able to force connecting on a specific device.. maybe
later...)
if( IsConnectedOnPrefered() )
return true;

//Server still reachable even if not on prefered AP (ex USB connection
or
...)
if( IsSQLServerAvailable(K_CONNECT_STRING) )
return true;
}

return false;
}

public static bool IsIpAssigned()
{
try
{

string sHostName = Dns.GetHostName();
IPHostEntry host = Dns.GetHostByName(sHostName);
string sIpAddr = host.AddressList[0].ToString();
return sIpAddr != IPAddress.Parse("127.0.0.1").ToString();
}
catch
{
return false;
}
}

private void RebindWireless()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
a.RebindAdapter();
return;
}
}
}

private bool IsSQLServerAvailable(string sConnectString)
{
try
{
SqlConnection con = new SqlConnection(sConnectString);
con.Open();
con.Close();
return true;
}
catch {}

return false;
}

public bool IsConnectedOnPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
if(a.AssociatedAccessPoint == null || a.AssociatedAccessPoint.Length ==
0) //Not connected on AP
return false;

AccessPointCollection oAColl = a.PreferredAccessPoints;
foreach(OpenNETCF.Net.AccessPoint access in oAColl)
{
if(access.Name == a.AssociatedAccessPoint)
return true;
}
}
}
return false;
}

private bool IsNearbyPrefered()
{
OpenNETCF.Net.AdapterCollection oCol =
OpenNETCF.Net.Networking.GetAdapters();
foreach(OpenNETCF.Net.Adapter a in oCol)
{
if(a.IsWireless)
{
AccessPointCollection oAColl = a.NearbyPreferredAccessPoints;
return oAColl.Count > 0;
}
}
return false;
}


:

One other thing you might try is doing a RebindAdapter() when you
think
you
might be back in range and want the adapter to try to reconnect.
There's
no
way to know if you really are there, unless you want to check the list
of
nearby APs, but rebinding *might* cause the adapter to reconnect to
one
of
its preferred APs...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top