Using Android-Tablet as an MQTT-Server

2020-03-30 06:24发布

问题:

I have read something about "messaging system" using the MQTT protocol. But i was always reading about the constellation: using Android as a MQTT-Client and a MQTT-Server which is not installed on a Android smartphone oder tablet (but as a standalone server).

Is it possible to use one Android-Tablet as a MQTT-Server and some other Android-Tablets (for example 5 Tablets) as MQTT-Clients??

And if this is possible, is it possible to use the one Android-Tablet which is a MQTT-Server, also as a MQTT-Client?

The communication between the Android-MQTT-Server-Tablet and the other tablets as MQTT-Client, should work over an WIFI-Router / WIFI-Access-Point.

Thank you in advance for helping.

回答1:

It is possible to use tablets as mqtt brokers (server) and mqtt clients. You'll have to use a client library on all tablets and a broker on one of them.

Here is pure java broker I have adapted to work on Android: https://github.com/interaktionsbyran/moquette Feel free to try it out!



回答2:

It's perfectly possible.

The hard bit would be working out which tablet would become the broker. One approach would be to use avahi (mDNS) to try and discover a broker, if none are found then set one up and advertise it via avahi.

As for actually finding a broker that will run on Android that would be anther challenge. I'm not aware of a public pure Java broker available, but you may be able to get mosquitto to compile as a native (arm) Android app, but you would need to write a service wrapper for it.