Reputation: 84813
I'm trying to get a "communication line" between a server app that uses MQTT for messaging and a web page where I want to see the messages in real time and send back messages to the server-side app.
I use mosquitto, Bottle and gevent on the server and I want to keep it as simple as possible. Using gevent I managed to receive the MQTT messages in a greenlet, put them in a queue and send the messages to the webpage in the websocket procedure which looks like this:
while True:
mqt = queue.get(True)
ws.send(mqt)
I can also send messages from the web page back to the server and MQTT like this (also through a queue):
while True:
msg = ws.receive()
queue2.put(msg)
However I want these two loops to work at the same time on the same websocket. Is there any way to combine them? For example does receive have a timeout? I guess I could use two separate websockets, but that would be a waste if I can do it with only one.
Upvotes: 2
Views: 885
Reputation: 59781
Why not just have messages delivered directly to the page using MQTT over Websockets? There are a number of brokers that support Websockets and the paho JavaScript client allows both subscribing and publishing of messages
Upvotes: 2