I have an app running on a computer using the following code but when I went back into the code today it does not work. The app is still running fine. It seems that the UPD_PacketArrived sub is never called anymore. The only thing I can think is possible is that there is something going on with the Network library (1.11) or it never should have worked and did anyway.
F.Y.I. The app looks for hardware using Microchip processors on the network.
When you click the Discover button the app sends a UDP packet to the network. The Microchip units on the network then send a response that the UDP_PacketArrived code processes and places the IP address of the unit into a listview.
Any ideas would be appreciated.
F.Y.I. The app looks for hardware using Microchip processors on the network.
When you click the Discover button the app sends a UDP packet to the network. The Microchip units on the network then send a response that the UDP_PacketArrived code processes and places the IP address of the unit into a listview.
Any ideas would be appreciated.
B4X:
'Activity module
Sub process_globals
Dim UDPSocket1 As UDPSocket
End Sub
Sub Globals
Dim DiscoverButton As Button
Dim ExitButton As Button
Dim ReceiverList As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
UDPSocket1.Initialize("UDP", 0, 8000)
End If
activity.LoadLayout("mainlayout")
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
ReceiverList.AddSingleLine(Packet.Host)
End Sub
Sub ReceiverList_ItemClick (Position As Int, Value As Object)
Dim p As PhoneIntents
StartActivity(p.OpenBrowser("http://" & Value))
End Sub
Sub DiscoverButton_Click
Dim Packet As UDPPacket
Dim data() As Byte
Dim DataString As String
DataString = "Discovery: Who is out there?\0" & Chr(13)
data = DataString.GetBytes("UTF8")
Packet.Initialize(data, "255.255.255.255", 30303)
If UDPSocket1.IsInitialized Then
UDPSocket1.Send(Packet)
Else
Msgbox("UPDSocket not initialized","Not initialized")
End If
End Sub