MQTT is a great network solution.
I never worked with it before. After trying it for a few days I think it is a very useful feature. It solves many of the difficult parts developers need to address when building projects that involve multiple machines.
An official B4J library which is also compatible with B4A will be released next week. There are already libraries for MQTT in the forum: https://www.b4x.com/android/forum/pages/results/?query=mqtt
However as this is an important feature I decided to provide an official library.
Here is a video of a small B4A / B4J example:
Note that the latency on the Android device comes from the screen cast.
The main code of this example:
I never worked with it before. After trying it for a few days I think it is a very useful feature. It solves many of the difficult parts developers need to address when building projects that involve multiple machines.
An official B4J library which is also compatible with B4A will be released next week. There are already libraries for MQTT in the forum: https://www.b4x.com/android/forum/pages/results/?query=mqtt
However as this is an important feature I decided to provide an official library.
Here is a video of a small B4A / B4J example:
Note that the latency on the Android device comes from the screen cast.
The main code of this example:
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Dim obj As Object = serializator.ConvertBytesToObject(Payload)
If obj Is CircleData Then
If Topic = mytopic Then Return 'the circle was already drawn
Dim cd As CircleData = obj
DrawCircleData(cd)
Else 'obj is string
Dim s As String = obj
Select s
Case "clear"
Canvas1.ClearRect(0, 0, Canvas1.Width, Canvas1.Height)
Case "close"
MainForm.Close
End Select
End If
End Sub
Sub Canvas1_MouseDragged (EventData As MouseEvent)
If mqtt.Connected = False Then Return
Dim cd As CircleData
cd.x = EventData.X
cd.y = EventData.Y
cd.clr = Rnd(0x80000000, -1)
DrawCircleData(cd)
mqtt.Publish(mytopic, serializator.ConvertObjectToBytes(cd))
End Sub