Choose cheapest connection...

M

Mobileboy36

Hi All,



If 2 network connections are available (GPRS and WLAN OR GPRS and LAN) the
pocket PC has to choose the 'cheapest' one, so in this case WLAN or LAN and
not GPRS.

So, my idea was to write an application called GPRS monitor, to control the
GPRS connection

Using functionality of OPENNETCF.NET 2.0 I 'm able to setup a connection
using VB.NET code.

But I'm encountering problems disconnecting the GPRS...My DisconnectGPRS
function (using OpenNETCF.Net.ConnectionManager) does not work...

On http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=7423 I found someone
with the same problem.



Is there yet a solution for this?

Am I doing something wrong?

Or does someone know a (third party) tool for pocket pc and Windows Ce to
give connections a priority value:

1. LAN

2. WLAN

3. GPRS



In addition you can find the code...



I hope to find a solution.

Any help would be greatly appreciated



best regards,

Mobile boy



Public Class ConnectionManager

Private _ConnectionManager As OpenNETCF.Net.ConnectionManager
Private _PingList As List(Of String)
Private _PingTimeOut As Integer
Private _PingInterval As Integer

Public Sub New(ByVal PingList As List(Of String), ByVal PingTimeOut As
Integer)
_ConnectionManager = New OpenNETCF.Net.ConnectionManager()
_PingList = PingList
_PingTimeOut = PingTimeOut
End Sub


Public Sub ConnectGPRS()
Dim MyDestinationInfoCollection As
OpenNETCF.Net.DestinationInfoCollection

MyDestinationInfoCollection = _ConnectionManager.EnumDestinations()

If Not Pingable() Then
Try
For Each Di As OpenNETCF.Net.DestinationInfo In
MyDestinationInfoCollection
Dim str As String = Di.Description

If (Di.Description.ToLower.StartsWith("the internet"))
Then
' het zou kunnen dat the internet op andere
operating systemen
' internet wordt of nog iets anders ;)
_ConnectionManager.Connect(Di.Guid, False,
OpenNETCF.Net.ConnectionMode.Synchronous)
End If
Next
Catch ex As Exception
End Try
End If
End Sub

Private Function Pingable() As Boolean
Dim MyPingobject As New OpenNETCF.Net.NetworkInformation.Ping
Dim MyPingReply As OpenNETCF.Net.NetworkInformation.PingReply
Dim En As System.Collections.Generic.List(Of String).Enumerator
Dim PingSucceeded As Boolean = False

Try
En = _PingList.GetEnumerator
While En.MoveNext And Not PingSucceeded
If En.Current <> "" Then
MyPingReply = MyPingobject.Send(En.Current,
_PingTimeOut)
PingSucceeded = (MyPingReply.Status =
OpenNETCF.Net.NetworkInformation.IPStatus.Success)
End If
End While

Catch ex As Exception
End Try
MsgBox("pingable: " & PingSucceeded)
Return PingSucceeded
End Function

Public Sub DisconnectGPRS()
' http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=7423
' Does not always work
Dim MyHttpWebRequest As System.Net.HttpWebRequest
Dim HttpResponse As System.Net.HttpWebResponse
Dim MyStreamReader As System.IO.StreamReader

Try
'MsgBox("Begin DisconnectGPRS")
'MyHttpWebRequest =
System.Net.WebRequest.Create("http://www.google.com")
'HttpResponse = CType(MyHttpWebRequest.GetResponse,
System.Net.HttpWebResponse)
'MyStreamReader = New
System.IO.StreamReader(HttpResponse.GetResponseStream())
'MyStreamReader.Close()

MsgBox("Before DisconnectGPRS")
_ConnectionManager.Disconnect()
MsgBox("After DisconnectGPRS")
Catch ex As Exception

End Try
End Sub
 
P

Peter Foot [MVP]

The reason is that the Disconnect method calls ConnMgrReleaseConnection.
This just tells connection manager that you no longer need the connection.
Because GPRS is an always-on connection type and doesn't incur any costs
when idle the system wont immediately drop the connection. The only way to
Disconnect the GPRS connection is to use Remote Access Service (RAS) APIs,
to get the handle of the current GPRS connection and call RasHangup.

Peter
 
M

Mobileboy36

Hi Peter,

Thank you for the explanation.
Does OpenNETcf implement the RAS API's?
No VB.NET or C# classes available iplmenting the RAS API's?

best regards,
Mobileboy
 
G

Guest

We don't have any RAS implementation, though there is one in our Support
Forums that someone maintains and is pretty active with development.


--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
 
M

Mobileboy36

Hi Peter,



I the past I was using RAS API's.
(http://beukers-hacking-zone.blogspot.com/)
My problem is that _RasUtil.dialUp monopolises the connection!!
So I was searching another solution to build a GPRS monitor that can keep
the connection always open and only closes it when I want.

I need it because when the device is docked and I have to be sure to
communicate over LAN, I need to close the gprs connection for a short time.



let's take the following situation:



App A uses the RAS API to setup the Gprs connection:
_RasUtil.dialUp(_RasEntryName, _RasUserName, _RasPassword)



At this moment, the connection is monopolized by App A.
You are not able for instance to visit a website using internet explorer. A
popup "Cannot connect" is fired.



Is it possible to create a Dialup method that makes a connection usable for
many programs (So for App A, App B, ...internet explorer). In other words, a
connection like the OS makes when setting it up manually...
I also need a Hangup method that closes the connection (for all programs).
In other words like the connection is closed by the OS when hanging it up
manually.



Best regards,

mobile Boy
 
G

Guest

Hi Peter,

Could you please help with sample VB.NET code on RAS/ dialup .

I did a PocketPC application and deployed on PSION Workabout PRO device
having WinCE.NET 4.20 OS.

The device has GRPS. Now, I need to wirte a module which whould be able to
do a dial-up connection to my network. I have the RAS numbers and login id &
password. But, I do not know how to do the dial up. Kinldy help me with
sample VB.NET code, if any.

many thanks in advance..
 

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