The UDP-Sample in the docu to the jnetwork-library didn't work at all.
It is obviously a 1 to 1 copy from the docu for the network lirary for B4A.
Here is what i came up with:
It is to remark that UDPSocket.Initialize must use the real port number. 0 as documented and used in the sample didn't work for me neither on my windows development system nor on my raspberryPI.
It is obviously a 1 to 1 copy from the docu for the network lirary for B4A.
Here is what i came up with:
B4X:
Sub Process_Globals
Private Msgbox As Msgboxes
Dim UDPSocket1 As UDPSocket
End Sub
Sub AppStart (Form1 As Form, Args() As String)
UDPSocket1.Initialize("UDP", 5000, 8000)
Dim Packet As UDPPacket
Dim data() As Byte
data = "Hello from RaspBerry".GetBytes("UTF8")
Packet.Initialize(data, "localhost", 5000)
UDPSocket1.Send(Packet)
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
Msgbox.show("Message received: " & msg, "")
End Sub
It is to remark that UDPSocket.Initialize must use the real port number. 0 as documented and used in the sample didn't work for me neither on my windows development system nor on my raspberryPI.