UDP listen on Galaxy SII - send ok, no listen

Miles

New Member
Licensed User
Longtime User
Hi Guys,

My first post here, hopefully not difficult a question I hope.

I have just tried the following code example. Sending from my phone to laptop (both are wifi) works perfectly. Sending from PC to phone, I get no msgbox popup. I looked at what wireshark thought it was doing (first on port 8000, then 5000)

Could my phone be refusing the connection attempt? (I had previously tried 1000 & 1001 because I already had some test software on those, same thing)



Port 8000

844 66.106174000 192.168.1.75 192.168.1.87 UDP 53 Source port: 62663 Destination port: irdmi

845 66.110363000 192.168.1.87 192.168.1.75 ICMP 81 Destination unreachable (Port unreachable)

Port 5000

1563 121.017658000 192.168.1.75 192.168.1.87 UDP 53 Source port: 62663 Destination port: 5000[Malformed Packet]

1564 121.021770000 192.168.1.87 192.168.1.75 ICMP 81 Destination unreachable (Port unreachable)




B4X:
Sub process_globals
    Dim UDPSocket1 As UDPSocket
End Sub

Sub Globals

End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        UDPSocket1.Initialize("UDP", 0, 8000)
    End If
    Dim Packet As UDPPacket
    Dim data() As Byte
    data = "Hello from Android".GetBytes("UTF8")
    Packet.Initialize(data, "192.168.1.100", 5000)
    UDPSocket1.Send(Packet)
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, "")
End Sub
 

agraham

Expert
Licensed User
Longtime User
From the help for UDPSocket.Initialize

Port - Local port to listen on. Passing 0 will cause the OS to choose an available port automatically.
Instead of explicitly identifying the port to listen on you are asking the OS to choose a port. In this case you then need to identify that port using UDPSocket.Port, or of course explicitly specify the one you want to use. If I am correct then it looks like the example in the library xml is incomplete.
 
Upvote 0

Miles

New Member
Licensed User
Longtime User
Thank you so much, that was the ticket. I tried port 1000 and the code paused at the init line, but a port of 1900 worked just fine.

I had just assumed that the example would just work and that 8000 was the port. So sorry not to have looked closer at the command structure.
 
Upvote 0
Top