Silently making a connection

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

The app I'm working on is one which can work both offline and online -
it synchronizes databases when it can, basically. Unfortunately, the
act of trying to make a web request "home" causes a load of dialog
boxes to appear on the device, which is inappropriate for the type of
app we're writing.

I've had a look on www.opennetcf.org, and I can't see anything in there
for testing/making an internet connection. Does anyone know of any
libraries available for this kind of thing?
 
In the new Smart Device Framework, you will find
OpenNETCF.Net.ConnectionManager. You can use this for making
connections. However, it's not silent (the notification bubble is
displayed, which is controlled by the underlying connection manager
APIs). One option would be to use RAS. You can either P/Invoke this
yourself or you can take a look at the IntelliProg RAS component.

--Neil

--
Neil Cowburn, MVP
Co-founder, OpenNETCF.org
Technologist, Content Master Ltd
Microsoft .NET Compact Framework MVP

www.opennetcf.org | www.contentmaster.com
 
Neil Cowburn said:
In the new Smart Device Framework, you will find
OpenNETCF.Net.ConnectionManager. You can use this for making
connections. However, it's not silent (the notification bubble is
displayed, which is controlled by the underlying connection manager
APIs). One option would be to use RAS. You can either P/Invoke this
yourself or you can take a look at the IntelliProg RAS component.

Great - thanks very much, I'll take a look.
 
Currently, the ConnectionManager class connects using
CONNMGR_PRIORITY_USERINTERACTIVE only. I'm working on changing this so
that developers can set the priority themselves. This way, you will be
able to use CONNMGR_PRIORITY_HIPRIBKGND which should connection silently.

--Neil



--
Neil Cowburn, MVP
Co-founder, OpenNETCF.org
Technologist, Content Master Ltd
Microsoft .NET Compact Framework MVP

www.opennetcf.org | www.contentmaster.com
 
Neil Cowburn said:
Currently, the ConnectionManager class connects using
CONNMGR_PRIORITY_USERINTERACTIVE only. I'm working on changing this so
that developers can set the priority themselves. This way, you will be
able to use CONNMGR_PRIORITY_HIPRIBKGND which should connection silently.

Excellent - thanks very much.

Bizarrely enough, we've found another way which seems to work - before
trying to use a WebRequest, we try to use a TcpClient to connect to the
same host/port. That appears to work (or fail) silently as far as the
user is concerned - if it throws an exception, I then just don't try to
use the WebRequest.

This seems a little bizarre to me as I'd have thought they'd be using
the same stack. Your change sounds like a much better way of doing it
though.
 
Neil Cowburn said:
In the new Smart Device Framework, you will find
OpenNETCF.Net.ConnectionManager. You can use this for making
connections. However, it's not silent (the notification bubble is
displayed, which is controlled by the underlying connection manager
APIs). One option would be to use RAS. You can either P/Invoke this
yourself or you can take a look at the IntelliProg RAS component.

Hmm... I've just been trying OpenNETCF.Net.ConnectionManager, and it's
not working quite as I'd expected. I have a little test app which has 4
buttons: Make WebRequest, Make TcpClient connection, ConnectionManager
connect, and ConnectionManager disconnect, along with a label showing
the current ConnectionManager state. All the ConnectionManager events
are set to toggle the label's text appropriately.

In the emulator, pretty much nothing happens - it always stays as
Disconnected. Fair enough, the emulator is a bit of a special case.

If I run it with an iPAQ in the cradle, however, I get the following
behaviour:

o If I click on ConnectionManager connect before anything else, it
changes from Disconnected to Connected. It then stays as Connected
until I click on ConnectionManager disconnect, at which point it goes
to Failed, after which I can't change the state.

o If I click on Make WebRequest or Make TcpClient connection, the state
stays as Disconnected (despite the fact that the web request / tcp
client succeeds), and then clicking on ConnectionManager connect
doesn't change the state.

Any ideas what might be going on?
 
Jon Skeet said:
o If I click on Make WebRequest or Make TcpClient connection, the state
stays as Disconnected (despite the fact that the web request / tcp
client succeeds), and then clicking on ConnectionManager connect
doesn't change the state.

Correction - it *sometimes* changes the state. Hmm... stranger and
stranger...
 
I use the WebRequest class (HTTPWebRequest) and I've never seen a dialog pop
up if it can't connect. If there is a problem, it raises an exception. How
are you getting dialog boxes to popup from WebRequest method calls?
 
Mike said:
I use the WebRequest class (HTTPWebRequest) and I've never seen a dialog pop
up if it can't connect. If there is a problem, it raises an exception. How
are you getting dialog boxes to popup from WebRequest method calls?

Just a simple WebRequest, using GetRequestStream and GetResponse. It
depends entirely on the device (and configuration) though - on some
devices the dialog boxes come up, and on others they don't. Very odd.

Bizarrely enough, I had another very strange connection issue today:
WebRequest worked, but TcpClient (to the same host and port) didn't -
when in the cradle. When using GPRS, all was fine. Very odd - but
fortunately not an issue for our app. Still, it would be nice to
understand...
 
Back
Top