09-17-2008 04:27 AM
I need to get the ipaddress of the current APN connected (GPRS or WiFi). I have seen in the forum some code like the following:
ServerSocketConnection scn = (ServerSocketConnection)Connector.open("socket://:
localIpAddress = scn.getLocalAddress();
but it doesn't return a valid IpAddress (i have checked that there is connection from my application, so it is not the problem).
On the other hand, I have seen that in the class RadioInfo there is a function getLocalIpAddress, but I don't know how to handle this...
09-17-2008 05:03 AM
As I understand it, when the device is connected without using WiFi, it is not a real IP Node, it is proxied by whatever it happens to be talking to. In a BES MDS Service it is the MDS, in a direct TCP service, it is a node some on the Wireless network provided by the carrier. So when connected in this way, the BlackBerry device does not have an IP address in the way you expect.
This is all changes when you connect directly via WiFi, then the device does have an IP address and can talk directly. Pre WiFi support there were no methods to obtain an IP Address that I could find in the Rim API.
So what happens when you have a wireless and WiFI device that is connected on both. That is an interesting question.
If you have a Wifi connection that has access to the same BES/MDS that you connect to wirelessly, then the device will (in my experience) route the traffic over WiFi. In that case, I suspect the socket will have an IP Address. I've not tested that it does, I will give this a go later, though hopefully someone else has done it.
However if you are using Direct TCP, (which I think you are), I'm not sure that the device will automatically route the traffic over WiFi, even if a WiFi connection is available. However this is not something I have tested and I can't remember seeing any documentation anywhere. I might try this later too, though hopefully someone else has done it. Actually this is something that you can try. If you go into your WiFi options, using WiFi diagnostics, you can see your IP Address. Is that what you see when the Socket is connected and you use getLocalAddress()? You could also try forcing a WiFi connection using the ";interface=wifi" suffix and see what you get using that connection method. If you get an IP Address with "interface=wifi", and not without, then I suspect you can't use Direct TCP and expect the BB to route it over WiFi.
Finally, I can't find a getLocalIPAddress in RadioInfo, did you mean getIpAddress(..); Sorry never looked at using this, so can't help.