UDP that worked once not working now

mleffler

Member
Licensed User
Longtime User
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.
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
 

mleffler

Member
Licensed User
Longtime User
Thanks

Thanks for the change I did not think about the brackets.
The line you point out is strange but it is what Microchip wants to see so I cant really change it.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Also note that UDP packets are not guaranteed to arrive (unlike TCP)....

So it could be caused by something in between as well...
 
Upvote 0

mleffler

Member
Licensed User
Longtime User
What's in log files

I did not seem much:
request time failed: java.net.SocketException: Address family not supported by protocol

That was the last line of the log file. It showed up after 4 lines like this:
GC_EXPLICIT freed 321K, 54% free 2538K/5511K, external 1625K/2137K, paused 112ms

I know UPD is not guaranteed but I have the previous version of the App running on the same network and it works perfectly using the same code.

I have also tried compiling the code and running and it does not work.

This is really strange.
 
Upvote 0

mleffler

Member
Licensed User
Longtime User
Still not working

I have tried the sample code under the UDP section in the manual and it does not work either. I cant seem to get any UDP code to work anymore.

My guess is that there was some change from Network 1.10 to Network 1.11 that is causing this. That is the only thing I can think of that changed.

I was just attempting to integrate two programs I had created before into one. Both programs including one that used the UDP code have been working for some time now. In the process I noticed the one using UDP would no longer work.
 
Upvote 0

mleffler

Member
Licensed User
Longtime User
More information

I got a copy of Network 1.10 and recompiled with that and the code now works.
I was even able to complete the program that I was trying to create starting with this code.
 
Upvote 0
Top