How to subscribe hivemq broker for web application(

Skip to first unread message

Sushil Bhat

Dec 29, 2016, 1:00:39 AM12/29/16
I am using HiveMQ broker to publish and subscribe.

I want to develop a subscriber Web application using ASP.Net C# and
M2Mqtt.Net.dll ( version : ). 

I am completely new for mqtt and hivemq, I dont know how to subscribe for web but i am able to subscribe for winforn/WPF application, same way i tried with web, but I think there is different way to do this I spent more time on google ans i got some link
using websocket we have to do this.
So my question is how to use websocket and javascript?
for this do i need some some library(like poho.js, mqtt.js) if yes how to use this? 
Can any one help me step by step what and how to do this?

Paul Fremantle

Dec 29, 2016, 4:03:24 AM12/29/16
To use a MQTT/WS and JS library, you need to do the following.

1) You need a server that supports MQTT/WS.

(I used the browserify option and it worked pretty easily)

This creates a browserMqtt.js which you import. 

Then you can use code like this in your JS <script> section:

<script src="./browserMqtt.js"></script>

   var client = mqtt.connect("wss://", options); 
      client.on("message", function(topic, payload) {
        message = JSON.parse(payload);
        if ('shortpress' in message) {
        document.getElementById('short').value=Date() ; 
        } else if ('longpress' in message) {
        document.getElementById('long').value=Date() ; 

Note my example is using secure WebSockets on port 8443, so yours will probably be different.


To learn more about MQTT please visit
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Paul Fremantle
Doctoral Researcher, University of Portsmouth, School of Computing
Visiting Scientist, Institute of the Architecture of Application Systems, Stuttgart
Visiting Lecturer, Software Engineering Programme, Oxford University
Co-Founder, WSO2
Apache Member and Committer
twitter: pzfreo / skype: paulfremantle / blog:
Reply all
Reply to author
0 new messages