0

I'm trying to make a realtime website with an android client. How does one connect eg mosquitto to PHP5, angularjs frontend and the android app?

Do I have to use nodeJs with socket.io for the angularjs frontend and then nodeJs server for all android MQTT messages?

This is all so confusing. I tried for a while with rabbit but got stuck :(

Yoker
  • 500
  • 4
  • 20

2 Answers2

0

If your android app needs to send messages to server only, you could use simple REST API. If you need server to the application messaging too, then you could try Cloud Messaging or just use simple WebSockets, which can give you real time performance. In the latter case you need Java implementation of WebSockets client, for instance, this one.

Realtime communication between the server and browser can be done using WebSockets too. You can use one of numerous PHP WebSockets implementation like this. Using Socket.IO could be a bit tricky, check this link to get more information.

In browser you can use standard WebSockets API. If you have requirements to support old browsers, which have no WebSockets support, then you need to check Socket.IO or SockJS library because they provide fallback mechanism.

Community
  • 1
  • 1
Eugene
  • 154
  • 1
  • 2
  • 10
  • This won't work. There needs to be a message broker to publish the messages and for all the clients to subscribe to this broker. – Yoker Mar 22 '16 at 14:26
0

Gonna answering to it if anyone is still stuck (6 years later)

Do I have to use nodeJs with socket.io for the angularjs frontend and then nodeJs server for all android MQTT messages?

That's the idea.

  1. Install a broker on your server (mosquitto works well with nodejs)
    a. add a first listener using mqtt protocol in your broker conf
    b. add a second listener for websocket protocol
  2. Connect your android client (the publisher) to your broker using the mqtt protocol
  3. Connect your website (the suscriber) using websocket protocol (https://github.com/php-mqtt/client for php)

The idea is to use the mqtt protocol as it suited for embedded devices messaging (lighter => faster, more reliable). The websocket protocol would be used as it is made for communication btw websites and servers.

Nano
  • 36
  • 3