Android Question UDPSocket

peggjones

Active Member
Licensed User
Longtime User
I am trying to use UDPSocket. How do I find out which port number to use?

I'm sure this is a daft question to many but I am completely new to any form of networking.

Many Thanks
 

peggjones

Active Member
Licensed User
Longtime User
Could you help me further please?

I'm playing with your UDPSocket example. I've set the IP correctly but the message never seems to be received. Any ideas why?
.
 
Upvote 0

peggjones

Active Member
Licensed User
Longtime User
There isn't enough information here.

Are you sending from the device to the desktop?

No from one tablet to another.

Sorry about lack of info. I know so little I don't know what is relevant. What I have done is as follows -

Copied your example.

Changed line 22 so it has the IP of one of the tablets.

Compiled the programme to both tablets.

Run the programme on both tablets.

I expected the receiving tablet to display "message received".

Many thanks, I do appreciate how difficult it is to understand someone who doesn't really understand what they're talking about!!
 
Upvote 0

peggjones

Active Member
Licensed User
Longtime User
Which example are you referring to?

Have you set the ports correctly?

The code I am using is

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, 5000)
End If
Dim Packet As UDPPacket
Dim data() As Byte
data = "Hello from Android".GetBytes("UTF8")
Packet.Initialize(data, "192.168.1.96", 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

I don't understand how the packetarrived routine knows which port it's listening on.

As far as I can see the packet is sent but never received.
 
Upvote 0
Top