Android Question How difficult is to use MQTT instead HTTP calls?

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there!

I have app that get data on a REST Server (i.e. a http server that returns JSON to consume)

I wrote this http server and I can change it to whatever protocol I desire to answer inquiries.

My problem is that I have frequently customers that are behind NAT and it is getting each time more difficult to get thru them. (internet providers are making it more and more difficult)

So I was wondering if I could use MQTT instead.

The idea would be to put a MQTT broker on an internet server (like amazon) and then make the local server that is behind the NAT connects there, and then any client app doing the same and them have a way to access the local server.

I have only know a overall concept of MQTT to have an idea if that is something possible to work. An external broker would work as a proxy and solve the problem theoretically.

Is MQTT the way to go?

I am using HTTPUTILS2 to connect to my local server. Since it is all in the same library it is not difficult to replace the calls to something else like MQTT and wait for the answer.

For those that already tested this, could it work?
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Hi,

I have not tested your particular case, but I have sent MQTT messages successfully containing JSON data, so I presume that it could work for your particular case. Be careful though, I think there is a size limitation (although I could be confusing this with FireBase Notifications - I use both)

Alternatively, you could consider using the jRDC2 server if you are querying a Data Server - like mySQL - fast, effective and safe as you can get - very easy to setup and use as well.

Enjoy !!
 
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
Why not move the http server to the internet?
I understand your question, however in this case it is worst. This a software for restaurants and they cannot afford to stop servicing if the internet is down. The server is http because is much flexible and easy to install. and does not depend on internet when installed locally. However some customers might want to access from outside.

In this case it is a big trouble. I was thinking in using mqtt, so the local server register itself in an external internet based mqtt broker to receive from there routed esquires. If internet connection is down, who is outside is gone, but how is inside is working fine. Then MQTT could be an alternative for routing messages, that in my case are JSON packages that simulates TABLES from database.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
HTTP is the most popular protocol and therefore it is also the most supported one. You may encounter networking issues with MQTT over the internet. Make sure to run some tests with different networks.

Another option is to run an online B4J http/websocket server and let the local server either poll the online server or connect with WebSockets.
 
Upvote 0
Top