Wish MulticastSocket

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please test this code (you need to add the PacketArrived event):
B4X:
Sub Process_Globals
   Private udp As UDPSocket
End Sub

Sub AppStart (Args() As String)
   CreateMulticastSocket("udp", 1900, "239.255.255.250")
   StartMessageLoop
End Sub

Sub CreateMulticastSocket (EventName As String, Port As Int, Group As String)
   Dim multi As JavaObject
   multi.InitializeNewInstance("java.net.MulticastSocket", Array(Port))
   Dim inet As JavaObject
   multi.RunMethod("joinGroup", Array(inet.InitializeStatic("java.net.InetAddress").RunMethod("getByName", Array(Group))))
   Dim jo As JavaObject = Me
   jo.RunMethod("SetMulticastSocket", Array(EventName, multi, udp))
End Sub

#if java
import java.net.*;
public static void SetMulticastSocket (String EventName, MulticastSocket socket, anywheresoftware.b4a.objects.SocketWrapper.UDPSocket udp) {
   udp.init(ba, EventName, 8192, socket);
}
#end if
 

aaronk

Well-Known Member
Licensed User
Longtime User
This worked. I see a lot of data being sent in the Log when I discover for devices.

Thanks heaps for your help on this.
 
Top