#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim udp_socket As UDPSocket
Dim udport As Int = 9999
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.
Private btnSend As Button
Private urlText As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
'in layer 1 just a edittext name urlText and a button name btnSend
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
udp_socket.Initialize("UDP",udport, 8000)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
udp_socket.Close
End Sub
''
Sub udp_send(s As String,desip As String,udpsocket As UDPSocket)
Dim Packet As UDPPacket
Dim data() As Byte
data = s.GetBytes("UTF-8")
Packet.Initialize(data, desip, 5000)
udpsocket.Send(Packet)
ToastMessageShow(" byte send " & s.ToUpperCase,False)
End Sub
Sub urlText_TextChanged (Old As String, New As String)
End Sub
'' can receive messages
Sub UDP_PacketArrived (Packet As UDPPacket)
If Packet.Length <= 0 Then Return
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF-8")
ToastMessageShow(msg,False)
End Sub
Sub btnSend_Click
udp_send(urlText.Text,"192.168.1.255",udp_socket)
End Sub