Accessing Connection Manager through .NET CF
Every so often someone asks on either an internal alias or our public newsgroup about the right way to establish a data connection using the Compact Framework. Most of the time you don't have to do this since many of the built-in classes will bring up the connection automatically, but sometimes it's necessary.
The API to use is called ConnMgrEstablishConnection(), and normally you'd P/Invoke to it to do all the magic. But there's a better way! The fine folks at OpenNETCF.org have a complete class library for interacting with Connection Manager as part of their Smart Device Framework. You can use the library to not only open or close connections, but also to listen for events like Connected, Disconnected, and ConnectionFailed.
[Author: Neil Enns]
Comments
- Anonymous
September 15, 2004
I'm the owner of the ConnectionManager class library for OpenNETCF.org. If anyone has any comments, suggestions, ideas then feel free to ping me. - Anonymous
September 15, 2004
I have tried using this in vain couple of months ago. But things might have changed btw now and then. We had a GPRS Modem we wanted to control. In the previous version of our project we used AppForge and I wrote the DLL to make use of the Connection Manager API to provide more control to the App. It worked well and was consistent. When we moved to .NET CF, I was excited to find this already done for me on OpenNETCF.org However when I started using this it was behaving inconsistently. Sometimes it just doesnt close the underlying connection. So again I took the same DLL I developed for AppForge and wrapped it up for CF. It does the job consistently. Is the Connection Manager API dependent on the hardware? When I go through the newsgroup, I find there are so many people complaining about the inconsistent nature of the Connection Manager API. Why is this so? - Anonymous
September 15, 2004
Depending on the platform you are on the behaviour of connection caching is different. In Smartphone/PPC 2003 and later Connection Manager won't necessarily tear down the GPRS connection when your app reports being done with it. This is by design, and is to support something called "always-on GPRS". You shouldn't worry about it. Just make sure that you call the appropriate API to say "I'm done using the network connection", and then let connection manager handle when to clean things up.
Neil - Anonymous
September 16, 2004
Neil is spot on. Calling the ConnMgrReleaseConnection does not always tidy up the active connection immediately because of "Always-On GPRS". If the connection handle passed to ConnMgrReleaseConnection is the last request handle that ConnMgr has for the handle's connection type, then the connection will be dropped. Otherwise, the connection will remain open for any other active requests.
Keeping a connection to a GPRS network should not be an issue anyway, since GPRS charges are (usually) for consumed bandwidth rather than based on connection time. - Anonymous
September 16, 2004
To be clear, even if you're the last person using the connection and you say you're done, Connection Manager in 2003 and later will NOT drop the connection by default. It'll leave it up indefinitely.
Neil - Anonymous
September 23, 2004
Hi,
I am working Pocket PC application which has a module which is suppose to dial internet and send some data through HTTP. Today it is two step process, where person has to manully dial the internet and then run my application to send data.
My question is how can I give dialer functionality in my application itself. I am using .NET for PPC development.
Thanks
../Sadashiv - Anonymous
September 23, 2004
Sadashiv,
You should download and use the OpenNETCF.org library I mention in my original post. Use connection manager to establish the Internet connection from within your own application.
Neil - Anonymous
October 07, 2004
Hi.
In OpenNetCF documentation's advise that work with instance members of this class are not safe to multiprocess operations. Now, to connect in my download's thread, im calling a web service to start connection (when I call it the connection starts), but i would like to have a class for do it to have more control over the GPRS connection.
PD: Excuse my poor english - Anonymous
October 08, 2004
Alfre,
You should talk to the OpenNetCF.org people. They have forums at their website, http://www.opennetcf.org/.
Neil - Anonymous
January 21, 2009
PingBack from http://www.keyongtech.com/1796197-inizialize-the-gprs-connection-with