iOS Question IOS get broadcast address

DickD

Active Member
Licensed User
I seem to be going around in circles on this so I'll start again. I'm converting my Android app which finds the broadcast address of the local router and then uses UDP autodiscover to locate other devices running my app. The code shown below works fine on Android but produces errors when copied to IOS. In particular the first line Dim niIterator results in the error "Are you missing a library reference?" There doesn't seem to be a JavaObject library for IOS.

I did get a response from Erel that said to use UDPSocket.GetBroadCastAddress in the network library for IOS but I could find not other reference other than the code shown below in that library.

Bottom line: how do I get the broadcast address in IOS?

B4X:
Private Sub GetBroadcastAddress As String
Dim niIterator As JavaObject
niIterator = niIterator.InitializeStatic("java.net.NetworkInterface").RunMethod("getNetworkInterfaces", Null)
Do While niIterator.RunMethod("hasMoreElements", Null)
Dim ni As JavaObject = niIterator.RunMethod("nextElement", Null)
If ni.RunMethod("isLoopback", Null) = False Then
Dim addresses As List = ni.RunMethod("getInterfaceAddresses", Null)
For Each ia As JavaObject In addresses
Dim broadcast As Object = ia.RunMethod("getBroadcast", Null)
If broadcast <> Null Then
Log("BroadcastAddress - " & broadcast & ", MyIP = " & MyIP)
Dim b As String = broadcast
Return b.SubString(1)
End If
Next
End If
Loop
Return ""
End Sub
 

DickD

Active Member
Licensed User
Why aren't you using UDPSocket.GetBroadcastAddress?
B4X:
Dim us As UDPSocket
Log(us.GetBroadcastAddress)
That worked thanks. I guess I was confused. I thought GetBroadcastAddress referred to the Sub I showed in my first posting. I didn't realize it was a member of the UDPSocket Library. I don't see this explained in the Network Library. Is this documented somewhere?
 
Upvote 0
Top