MQTT – Message Queuing Telemetry Transport, is an application level network protocol for simple and lightweight network communication.
The communication in MQTT is done between multiple clients. There is no server component. There is a broker component. The broker is a “black box” that handles the clients. It just needs to run.
Whenever you find yourself implementing a solution based on TCP sockets, stop for a moment and give MQTT a try. It is likely to be simpler and in most cases work better.
MQTT is a publish-subscribe protocol. Clients subscribe to various topics and clients publish messages to a topic. The broker is responsible for distributing the messages to all subscribed clients.
MQTT clients libraries are available for all B4X products. There are broker libraries available for B4A and B4J. You can also run any other broker implementation including internet based, cloud brokers.
MQTT tutorial: https://www.b4x.com/android/forum/threads/iot-mqtt-protocol.59471/#content
Code to make a connection and try to reconnect when needed: https://www.b4x.com/android/forum/threads/b4x-mqtt-connect-reconnect.80815/#content