I've tested with:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Dim UDPSocket1 As UDPSocket
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
NavControl.ShowPage(Page1)
Dim server As ServerSocket 'ignore
Log(server.GetMyWifiIp)
UDPSocket1.Initialize("UDP", 14000, 8000)
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
Log("Message received: " & msg)
End Sub
And B4J code:
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
Dim socket As UDPSocket
socket.Initialize("socket", 11111, 8192)
Do While True
Dim udp As UDPPacket
udp.Initialize(DateTime.Time(DateTime.Now).GetBytes("utf8"), "192.168.0.107", 14000)
socket.Send(udp)
Sleep(1000)
Loop
End Sub
B4i logs:
Application_Start
192.168.0.107
Application_Active
Message received: 16:07:05
Message received: 16:07:06
Message received: 16:07:07
Message received: 16:07:08
Message received: 16:07:09
Message received: 16:07:10
Message received: 16:07:11
Message received: 16:07:12
Message received: 16:07:13
Message received: 16:07:14
Message received: 16:07:15
Message received: 16:07:16
Message received: 16:07:17
...