B4A Library [B4X] InetStatus - Check if Internet interfaces are enabled + type (WiFi/Cell/LAN)

The library has changed its name because it confused some users. All updates will be made in the following post:



Older post

I am almost finished a project to add the possibility of ping to this library and it will allow you to control if the external Internet connection is active. In the example screens, where it says "connected?", it actually refers to whether the virtual Wi-Fi/data interface on the cell phone or the network card on the PC is enabled

  • InetStatus
    • Events
      • SocketStarted (Port As Int)
        Triggers when the socket starts
      • SocketClosed
        Triggers when socket closes
      • ConnectionStatusChanged (IPStatus As tpeIPs)
        Triggers when there is a change in the connection. Returns a tpeIPs type variable. See details below
      • Error (Msg As String)
        Trigger when an error occurs, they can be the following:
        • Socket not initialized.
        • The IP format is not valid. Includes IPv4 or IPv6
        • Can't initialize socket.
        • Can't initialize socket on port NUM_OF_PORT
        • Socket is already initialized on port NUM_OF_PORT
    • Types
      • tpeIPs (IsConnected As Boolean, ConnType As String, IP As String)
        • IsConnected: True or False
        • ConnType: NONE (B4X), WIFI (B4A/B4I), CELL (B4A/B4I) or LAN (B4J)
        • IP: Valid IPv4 or IPv6
    • Fields
      • Tag As Object
        Default: Null (It is always valuable to have a Tag field ;))
      • IPs As tpeIPs
        Default: IsConnected = False, ConnType = "NONE", IP: "127.0.0.1"
    • Methods
      • Initialize (CallBack As Object, EventName As String)
        Initializes the object. Add parameters to this method.
      • Start (Port As Int)
        Start the socket on the desired port
        IMPORTANT: The number can be 0 or one greater than or equal to 1025 up to 65535.
        Search on
        this list of ports for one that is available and does not conflict with another service
      • GetIfChanged (ForceRaiseStatus As Boolean)
        Update IPs variable
        Default: False. If ForceRaiseStatus is
        True, raise event ConnectionStatusChanged whether the IP has changed or not
      • Close
        Close socket
Change log:
  • 1.00
    • Release
  • 1.01
    • Add DependsOn XUI, iXUI and jXUI in manifest.txt file
Implementation Summary:
Sub Class_Globals
    Private iSts As InetStatus
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    iSts.Initialize(Me, "CheckStatus")
    iSts.Start(0)
End Sub

Private Sub CheckStatus_SocketStarted (Port As Int)
    Log(Port.As (String))
End Sub

Private Sub CheckStatus_ConnectionStatusChanged (IPStatus As tpeIPs)
    Log("Connected? " & IPStatus.IsConnected.As (String))
    Log("Type " & IPStatus.ConnType)
    Log("IP " & IPStatus.IP)
End Sub

Private Sub CheckStatus_Error (Msg As String)
    Log(Msg)
End Sub



B4IB4AB4J
1719013872672.png
1719013972584.png
1719014110058.png
 

Attachments

  • CheckInternet.zip
    11.5 KB · Views: 43
  • SP InetStatus.b4xlib
    2.1 KB · Views: 35
Last edited:

serg992313

Member
I am connected to the internet via an Apple router. Just launched the provided example for B4J and disconnected the LAN internet cable from the router. Unfortunately, I got the result that the internet is still available. Do I need to set any extra parameters to correctly verify that the internet is still available?
 

Sergio Haurat

Active Member
Licensed User
Longtime User
I am connected to the internet via an Apple router. Just launched the provided example for B4J and disconnected the LAN internet cable from the router. Unfortunately, I got the result that the internet is still available. Do I need to set any extra parameters to correctly verify that the internet is still available?
Hello @serg992313, the library does not detect if your device has internet access; it only checks if the "virtual" interface for WiFi and mobile data, or PC network is enabled. In your case, you would need to disable the network adapter, not just disconnect the cable.
For the function you need, I am adding the option to ping an external site to the library. If it fails, it will notify you that the Internet is not available.. The property will be called something like "Is internet available?" and will return true or false.

I hope my response is understandable, I do not speak English.
 
Top