Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private udp As UDPSocket
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
CreateMulticastSocket("udp", 1900, "239.255.255.250")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
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 void SetMulticastSocket (String EventName, MulticastSocket socket, anywheresoftware.b4a.objects.SocketWrapper.UDPSocket udp) {
udp.init(getBA(), EventName, 8192, socket);
}
#end if