Android Question Get UDP Broadcast crash on B4A

max123

Active Member
Licensed User
Hi all,

this Snippet works well on B4J. On B4A this works in Debug mode only but crash in Release mode on my Nexus 7 SE. 😢
https://www.b4x.com/android/forum/threads/udp-broadcast-address.75694/

Another question, on B4J and on B4A Debug mode it return 192.168.178.255, but broadcast IP Address is not in range 234.x.x.x - 239.x.x.x ?
What I need is to send UDP audio stream from ESP8266 to more Android and Desktop devices, so I need to discover my network broadcast address, or maybe I misconfused with multicast?
Maybe is my FritzBox 7530 that reroute it ?

Any help is appreciated.

Many thanks

Here the B4A log in release mode:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_getbroadcastaddress (java line: 369)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at b4a.example.broadcast.ip.main._getbroadcastaddress(main.java:369)
at b4a.example.broadcast.ip.main._activity_create(main.java:337)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at b4a.example.broadcast.ip.main.afterFirstLayout(main.java:102)
at b4a.example.broadcast.ip.main.access$000(main.java:17)
at b4a.example.broadcast.ip.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.net.SocketException
at java.net.NetworkInterface.rethrowAsSocketException(NetworkInterface.java:248)
at java.net.NetworkInterface.collectIpv4Address(NetworkInterface.java:208)
at java.net.NetworkInterface.getByNameInternal(NetworkInterface.java:127)
at java.net.NetworkInterface.getNetworkInterfacesList(NetworkInterface.java:309)
at java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:298)
... 16 more
Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
at libcore.io.Posix.socket(Native Method)
at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
at java.net.NetworkInterface.collectIpv4Address(NetworkInterface.java:193)
... 19 more
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It needs the android.permission.INTERNET permission. It will be added if you add a UdpSocket object.

You can also add it with AddPermission in the manifest editor.

Another question, on B4J and on B4A Debug mode it return 192.168.178.255, but broadcast IP Address is not in range 234.x.x.x - 239.x.x.x ?
The broadcast address looks correct. Try it.
 
Upvote 0

max123

Active Member
Licensed User
Ok, that worked, many thanks Erel ;), and for my other question you think it is right or I'm wrong?

Many thanks
 
Last edited:
Upvote 0
Top