3

I'm working on a project, which should connect to servers through wifi/gprs. Project is an application for Windows CE 6.0 device, I'm writing in Visual Studio 2008 on C#.

I have two severs to work with. The first I have to connect via wifi, second - via gprs. So I need to know, how can I change the method of connecting between wifi and gprs?

I found and tried this way: I turn on both wifi and gprs on my device. So I work via wifi because it has a higher priority. When I need to work via gprs, I turn off wifi (SetDevicePower function). But when I turn wifi on, it doesn't connect back to my Preferred Network.

Also I heard about the way to change priority between gprs/wifi in OS priority table programmatically, but I didn't find any information about how to do this.

I hope you can help me.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
Igor Ryzhov
  • 171
  • 1
  • 1
  • 13

1 Answers1

2

I would use the route command from a shell.

lets assume

server1 ip: 123.123.123.1
server2 ip: 123.123.123.2

wifi ip   : 192.168.1.101
   gateway: 192.168.1.1

gprs ip   : 10.1.2.3
   gateway: 10.1.1.1

Now you can excute in a command prompt

route add 123.123.123.1 MASK 255.255.255.255 192.168.1.1

and

route add: 123.123.123.2 MASK 255.255.255.255 10.1.1.1

This should route all trafic to server 1 over wifi and to server 2 over gprs, without changing a single line of code in your app.

You can verify it worked with

tracert 123.123.123.1
tracert 123.123.123.2

However, you could use your app to periodically perform this task (I assume gprs ip could change from time to time) with Process.Start(...)

- delete route 1
- add route 1
- delete route 2
- add route 2

You even could specify the interface with the IF 2 switch (route list prints the interface id for your network cards).

Another interesting post to read is this one: http://ce4all.blogspot.com/2007/05/routing-ip-traffic-via-specified.html

The author uses the GetAdapterAddresses() and CreateIpForwardEntry() P/Invokes:

http://msdn.microsoft.com/en-us/library/ms927384.aspx

http://msdn.microsoft.com/en-us/library/ee495149%28v=winembedded.60%29.aspx

Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189
  • I tried this way. `GetAdapterAddresses()` works properly, so I've got WiFi and GPRS IP. But I don't understand how to use CreateIpForwardEntry()`. Where can I get data for `dwForwardNextHop` and `dwForwardIfIndex`. Also where can I get gateway for wifi and gprs? – Igor Ryzhov Mar 10 '12 at 01:28