I tried to start this code from this thread https://www.b4x.com/android/forum/threads/multicastsocket.73437/#post-466959 but the error message appears
javac 1.8.0_212
src\b4j\example\b4xmainpage.java:183: error: non-static variable ba cannot be referenced from a static context
udp.init(ba, EventName, 8192, socket);
Code
Why?
javac 1.8.0_212
src\b4j\example\b4xmainpage.java:183: error: non-static variable ba cannot be referenced from a static context
udp.init(ba, EventName, 8192, socket);
Code
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
Sub udp_PacketArrived (Packet As UDPPacket)
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