njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
538 stars 135 forks source link

Websocket support #123

Closed colinl closed 4 years ago

colinl commented 4 years ago

Does the gem support mqtt via websockets? I guess not since I can't see any reference to it.

njh commented 4 years ago

It doesn't. What is the benefit of using websockets from outside the browser?

Maybe you could setup a proxy?

https://github.com/vi/websocat

colinl commented 4 years ago

I am using Traefik with vernemq broker with internet access to the broker coming in on wss. Mostly for access from remote node-red systems and that is working well, Traefik handles wss ok. However I now need access from a Rails server. I haven't had any success persuading Traefik to handle mqtt, and can't find any examples of anyone doing it, so I was hoping this gem would solve my problem.

njh commented 4 years ago

It looks like Traefik supports routing TCP + TLS + SNI, is that not sufficient?

colinl commented 4 years ago

If I could make it go then yes. There are very few examples of Traefik tcp routers as opposed to http. I am sure it is doable that way, but not easy to get going unless you know the appropriate incantations, apparently, once you do it is not doubt trivial. I am sure I will eventually make that work, or find an alternative solution. I have node-red running on the same server as the Rails app, so I expect I can find a way of getting the data across to node-red and hence to MQTT.

colinl commented 4 years ago

In case anyone finds this I have solved the problem. Node-red and the broker are on the same local network so I don't need to use a secure connection to the broker. By using something along the lines of the accepted solution to this post then I am able to access the broker locally using mqtt at port 1883 whilst still using wss for remote connections. Only ports 80 and 443 are forwarded to Traefik in my router. Thanks for the help.