Note: For what it is worth, this works on Android from B4A, but not on iOS from B4i.
My company produces Linux media servers that listen for a UDP broadcasted string on port 3662 and will respond with a UDP packet on port 3661. I have coded up a Broadcast as UDP Socket and Listener as UDPSocket.
Wireshark and the 20 devices on my network do not show the UDP packet. The log shows in gray text "error sending data". If I change the broadcast IP from 255.255.255.255 to a specific (known) media server IP, I see the UDP packet and the media server responds and the response is processed in Listener_PacketArrived.
Is my broadcast packet not formed correctly? Is UDP broadcasting not allowed in iOS?
My company produces Linux media servers that listen for a UDP broadcasted string on port 3662 and will respond with a UDP packet on port 3661. I have coded up a Broadcast as UDP Socket and Listener as UDPSocket.
B4X:
Sub Class_Globals
Dim Broadcast As UDPSocket
Dim Listener As UDPSocket
Dim BROADCAST_PORT As Int : BROADCAST_PORT = 3662
Dim REPLY_PORT As Int : REPLY_PORT = 3661
Dim LISTEN_TIME As Int : LISTEN_TIME = 5 'in seconds
Dim BROADCAST_MESSAGE As String : BROADCAST_MESSAGE = "ARQFIND ROLLCALL:\x00"
Dim REPLY_MESSAGE As String : REPLY_MESSAGE = "ROLLCALL REPLY:\n"
End Sub
Sub btnFindServers_Click
Broadcast.Initialize("Broadcast", BROADCAST_PORT, 1024)
Listener.Initialize("Listener", REPLY_PORT, 1024)
Dim Packet As UDPPacket
Packet.Initialize(BROADCAST_MESSAGE.GetBytes("UTF8"), "255.255.255.255", BROADCAST_PORT)
Broadcast.Send(Packet)
End Sub
Sub Listener_PacketArrived(Packet As Object)
Log("Listener_PacketArrived")
Dim msg As String
Dim dp As UDPPacket = Packet
Log(dp.HostAddress)
msg = BytesToString(dp.Data, dp.Offset, dp.Length, "UTF8")
Log("ARQFind Response: " & msg)
End Sub
Wireshark and the 20 devices on my network do not show the UDP packet. The log shows in gray text "error sending data". If I change the broadcast IP from 255.255.255.255 to a specific (known) media server IP, I see the UDP packet and the media server responds and the response is processed in Listener_PacketArrived.
Is my broadcast packet not formed correctly? Is UDP broadcasting not allowed in iOS?