iOS Question GetBroadcastAddress

simonwilliamson

Member
Licensed User
Hi all,
I have a situation where my B4x project could be on a PC or iPad that is connected to several networks at the same time and I need to use the UDPSocket1.GetBroadcastAddress to discover a certain device (where I can't be certain which network it is on).
For B4j & B4a I can use the solution here: Link to loop through and get several broadcast addresses back so I can then broadcast to each one in turn.
My question is how can I replicate this solution in B4i so I can discover all networks and it's broadcast address?
Regards,
Simon
 
Solution
Try this:
B4X:
Private Sub GetAllAddresses(broadcast As String) As Map
    Dim no As NativeObject
    Return NSDictionaryToMap(no.Initialize("B4IServerSocketWrapper").RunMethod("getIPAddresses:", Array(broadcast)))
End Sub

Private Sub NSDictionaryToMap(Dictionary As Object) As Map
    Dim NewMap As NativeObject
    NewMap = NewMap.Initialize("B4IMap").RunMethod("convertToMap:",Array(Dictionary))
    Return NewMap
End Sub

Dim m As Map = GetAllAddresses(True)

Make sure that iNetwork library is referenced.

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Private Sub GetAllAddresses(broadcast As String) As Map
    Dim no As NativeObject
    Return NSDictionaryToMap(no.Initialize("B4IServerSocketWrapper").RunMethod("getIPAddresses:", Array(broadcast)))
End Sub

Private Sub NSDictionaryToMap(Dictionary As Object) As Map
    Dim NewMap As NativeObject
    NewMap = NewMap.Initialize("B4IMap").RunMethod("convertToMap:",Array(Dictionary))
    Return NewMap
End Sub

Dim m As Map = GetAllAddresses(True)

Make sure that iNetwork library is referenced.
 
Upvote 0
Solution
Top