B4J Question [RESOLVED] UDP Sockets: B4A Client to B4J Server


Well-Known Member
Licensed User
Longtime User
Hi all

I am developing a B4J server to act as PTT server, the B4A client is currently based on Erels PTT Wifi Code (modified to work with UDP, removed BT etc). The B4J server is purely using UDP sockets. The server has 2 class's, each class has a UDP socket in it.

The first class, the listen class is used to register a user so they can hear the audio, the other class is to handle a user user is speaking. There is a much bigger picture behind all of this.

Wen a client connects to the listen class the i.e
private Sub udp_PacketArrived (Packet As UDPPacket)
   Dim connection As tConnection
   connection.imei = BytesToString(Packet.Data,Packet.Offset, Packet.Length,"UTF-8")
   connection.last_ping = DateTime.Now
   connection.rhost = Packet.HostAddress
   connection.rport = Packet.Port

   Log("LISTEN " & DateTime.Time(DateTime.Now) & " -  " & _
           connection.rhost & ":" & connection.rport & " - " & connection.imei )
   ' // we are testing a response
   Dim p As UDPPacket, res As String = "hello " & connection.imei
   Dim data() As Byte = res.GetBytes("UTF8")
   p.Initialize(data, Packet.HostAddress,Packet.Port)

End Sub

The problem I am having is the simple "hello" response packet is not be returned to the client.

Anyone have any thoughts on this ?


Last edited:


B4X founder
Staff member
Licensed User
Longtime User
Create a new project and try to send packets to the B4A app. Does it work? If not then the problem is in your B4A code.

This line suggests that you should create a class that handles the connection. You will then have a class instance for each connection, instead of this map. It will be simpler.
Upvote 0