Android Question B4X - Consistently Determine if WIFI is available and connected - B4i, B4J, B4A

MrKim

Well-Known Member
Licensed User
Longtime User
I tried this code (Along with a lot of other things but this works for all three)
B4X:
    Dim IP As ServerSocket
    Dim myIp As String = IP.GetMyIP
    IP.Close
    Return myIp

All return a valid looking IP if they are connected. However if I turn off the WIFI on each device, or don't connect to a router I get the following.

B4X:
B4J: fe80:0:0:0:9d4c:3fa6:46:857%wlan0
B4i: 127.0.0.1
B4A: 26.0.28.37

Initializing ServerSocket makes no difference and as I understand it is not necessary to get the ip.
I seem to vaguely remember 127.0.0.1 from my bouts with wifi a few years ago on android. That meant you were not connected. But now I get 26.0.28.37?

So, my question is really this:
Is this the code I should be using to verify that the user is connected to a network and if so,
What do I look for to know when they are not connected?
B4i I think I get - if it is 127.0.0.1 then not connected.
B4J - Do I parse it to see if it is in valid ipv4 format?
B4A I am lost. Is 26.0.28.37 the new 127.0.0.1 for android?

Thanks for your help.
 

MomoWen

Member
Licensed User
The best way is to not make any test and just try to connect. If it works it works and if not then there is no valid connection.
I was trying to connect and the interface froze in the event of a sudden disconnect (Ethernet).I have enabled unmonitor network.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
B4A I am lost. Is 26.0.28.37 the new 127.0.0.1 for android?
The 127.0.0.1 so-called Loopback address is a special IP number (127.0.0.1) that is designated for the software loopback interface of a machine. The loopback interface has no hardware associated with it, and it is not physically connected to a network. It's purpose is and it is always available to reroute a network packet back to the sender without any change. It has nothing to or any relation to the connect status of your wifi interface.
The address 26.0.28.37 could be a defined or retrieved network address of the wifi interface. Be aware that some driver software assign a valid privet 192.168.x.y address to a not connected wifi interface.
As always Erel has given the right answer:
If it works it works and if not then there is no valid connection.
 
Upvote 0
Top