Sub Process_Globals
Dim UDPSocket1 As UDPSocket
Dim Server As ServerSocket
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ButtonSend As Button
Dim EditData As EditText
Dim EditDest As EditText
Dim LbReceived As Label
Dim Timer1 As Timer
Dim DestAddress As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
UDPSocket1.Initialize("UDP", 6000, 8000)
End If
Activity.LoadLayout("udp")
End Sub
Sub Activity_Resume
Timer1.Initialize("Timer1", 400)
UDPConnect
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled = False
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
'Msgbox("Message received: " & msg , "")
LbReceived.Text = msg
Try
'Msgbox(" from host " & Packet.HostAddress, "")
Catch
Msgbox(" error from host ", "")
End Try
If msg = "eBreathalyzer" Then
Timer1.Enabled = True
DestAddress = Packet.HostAddress
End If
End Sub
Sub ButtonSend_Click
UDPConnect
ToastMessageShow("Message send = " &EditData.Text, False)
End Sub
Sub Timer1_Tick
Dim Packet As UDPPacket
Dim Dest As String
Dim data() As Byte
data = EditData.text.GetBytes("UTF8")
Dest = DestAddress
Packet.Initialize(data, Dest, 6000)
UDPSocket1.Send(Packet)
'ToastMessageShow("Message send = " &EditData.Text, False)
End Sub
Sub UDPConnect
Dim Packet As UDPPacket
Dim Dest As String
Dim data() As Byte
data = "ID".GetBytes("UTF8")
Dest = "255.255.255.255"
Packet.Initialize(data, Dest, 6000)
UDPSocket1.Send(Packet)
End Sub