B4J Question UDP Communication

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I have a B4A Application that runs in Android, that is composed of three separate parts, and is used to manage queues in restaurants,
One offers a set of language choices to the user, that then selects how many persons are to be seated and them send the request via UDP, via port 8000 to another part of the Application that receives it (Request number, language and number of persons) and stores it in a BD and a table view. The manager then when a table is available with the requested seats, calls the ticket that sends the number to a wide screen with a third Andoid APP that speaks the number if the requested language.
so far so go, all the three apps work flawlessly in android.
now, the costumer wanted a Windows KIOSK, with a large format lcd touch screen to improve the costumer experience while waiting to be called.
The code is the same as the one used in android and ported from B4A to B4J. In windows, sometimes there is a delay in the response time beetween apps. Is there something that must be made differently while communicting in Windows via UDP ?

Below the code that Sends and receives the data, it is the same in android

Sub btn_confirm_Click
'routine that generates a sequential or a random request number
    If File.Exists(File.dirApp,"seq") = True Then
    End If
    Dim DataPedido As String = DateTime.Date(DateTime.Now)
    Dim HoraPedido As String = DateTime.Time(DateTime.Now)
    Dim SqlExpression As String = "INSERT INTO Pedidos (Numero, Data, Hora, Pax, Lingua, Chamado) VALUES ('" & CurRnd & "','" & DataPedido & "','" & HoraPedido & "','" & CurrentNumOfPax & "','" & CurrentChoice & "','Vazio')"
End Sub

Sub Send2All(Msg2Send As String)

    Dim TkUp As UDPPacket
    Dim data() As Byte
End Sub

private Sub UDP_PacketArrived(Packet As UDPPacket)
    Dim msg As String = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
   ' The other App sends back to the UDP port 8000 a string composed of "ACK" and the request number
    If Sf.Left(msg,3) ="ACK" Then
        CurrentNumOfPax = 1
        Num_pax.Text = CurrentNumOfPax
        CurrentChoice ="PT"
        pedidos.Visible = False
        bandeiras.Visible = True
    End If

End Sub

Pedro Caldeira

Active Member
Licensed User
Longtime User
Why are you using UDP here? UDP is non-reliable. Assuming that there are multiple clients then your best option is to use MQTT. It will be much simpler and will work better.

in android it works nicely with UDP, not so much in Windows
And the MTQQ works in B4J ?
Upvote 0