regarding websockets in Mosquitto

1,565 views
Skip to first unread message

Suman Patro

unread,
Mar 22, 2016, 1:54:17 PM3/22/16
to MQTT
Hello,

I have enabled websockets on mosquito and everything works fine when webclients are publishers and subscribers but when I try to subscribe from a web client and publish from a normal mosquito client, the publisher gives an error: Connection was lost. Everything is done using websockets protocol. Mosquitto used is Mosquitto 1.4.2 and webclient is http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git. What is the cause of this problem and how should it be resolved?. Any help is highly appreciated.

Thanks and regards,

Suman

Jan-Piet Mens

unread,
Mar 22, 2016, 2:08:12 PM3/22/16
to mq...@googlegroups.com
> webclients are publishers and subscribers but when I try to subscribe from
> a web client and publish from a normal mosquito client, the publisher gives
> an error: Connection was lost. Everything is done using websockets
> protocol.

If, by "normal mosquitto client" you mean mosquitto_pub, the reason is
simple: mosquitto_{pub,sub} do not support Websockets.

-JP

Suman Patro

unread,
Mar 22, 2016, 2:37:37 PM3/22/16
to MQTT
Thank you very much, Sir .But how do I  make normal mosquitto client publish messages  and websocket client receive the published message over the  subscribed topic? Please answer. 

Karl Palsson

unread,
Mar 24, 2016, 5:13:30 PM3/24/16
to mq...@googlegroups.com

Suman Patro <spat...@gmail.com> wrote:
> Hello,
>
> I have enabled websockets on mosquito and everything works fine
> when webclients are publishers and subscribers but when I try
> to subscribe from a web client and publish from a normal
> mosquito client, the publisher gives an error: Connection was
> lost. Everything is done using websockets protocol. Mosquitto
> used is Mosquitto 1.4.2 and webclient is
> *http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git*
> <http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git>.
> What is the cause of this problem and how should it be
> resolved?. Any help is highly appreciated.

Is it possible you're using the same client id on both places?

Suman Patro

unread,
Mar 25, 2016, 1:40:06 PM3/25/16
to mq...@googlegroups.com
I do not provide any client id , Karl and I think Jan-Piet-Mens is right .But I would like to know how do I  make normal mosquitto client publish messages  and websocket client receive the published message over the  subscribed topic?
Thanks and regards,
Suman


--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to a topic in the Google Groups "MQTT" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mqtt/-cHmbbwOkbU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Hans Jespersen

unread,
Mar 25, 2016, 3:51:50 PM3/25/16
to MQTT
That should just work. Publishers and subscribers do not need to use the same transport protocol, they just need to connect to the same mqtt broker and send and receive on matching topics. I think your problem is just that your  "normal" publisher is just not working correctly. This could be because of the options you are using to publish are incorrect or that your mosquitto broker is not setup properly to handle both web socket and non-websocket clients. Are you using different ports for the publisher and the subscriber because their will be separate a websocket listen port (80 or whatever you configured) which is not the same as the tcp listen port (default of 1883). Perhaps your publisher is not working because you are trying to connect to the wrong port?

-hans

Suman Patro

unread,
Mar 26, 2016, 6:00:22 AM3/26/16
to MQTT
I have a mosquito.exe that runs on port 1883 for mqtt and on port 9001 for websockets protocol. Normal publishing and subscribing  is done right i.e w.r.t port 1883. , clients being mosquitto_pub.cpp and mosquito_sub.cpp but when I try to run the clients on port 9001, the publisher client shows an error: connection was lost.

Hans Jespersen

unread,
Mar 26, 2016, 2:17:51 PM3/26/16
to MQTT
I assume you are using a Web client to publish using websockets on port 9001. Is the error in your browser console? Can you share the JavaScript you are using to publish from the web client?

Suman Patro

unread,
Mar 26, 2016, 3:44:59 PM3/26/16
to mq...@googlegroups.com
I'll again try and configure things and will update you soon on this, Hans. One more thing that has popped up is  with respect to websockets itself, if mosquito has websockets module then what is the need of an external web server?? If no external web server is needed , then what should be the procedure to incorporate web server functionalities into the broker itself?

On Sat, Mar 26, 2016 at 11:47 PM, Hans Jespersen <hans.je...@gmail.com> wrote:
I assume you are using a Web client to publish using websockets on port 9001. Is the error in your browser console? Can you share the JavaScript you are using to publish from the web client?

Hans Jespersen

unread,
Mar 26, 2016, 6:43:48 PM3/26/16
to MQTT
The mosquitto broker (mosquitto,exe) supports mqtt over websockets but the mosquitto_pub and mosquitto_sub clients do not. That is what JP said before.
If you want to test out a publisher or subscriber that uses mqtt over websockets you will have to either use a web client (with the Paho Javascript client libraries) or get another command line client other than mosquitto_pub that DOES support mqtt over websockets. For example the MQTT.js command line client for node.js ( see https://github.com/mqttjs/MQTT.js)

-hans

Luke Oglesbee

unread,
Apr 25, 2016, 6:12:19 PM4/25/16
to MQTT
Hi Suman,

I'm currently dealing with the same problem you described. Do you have an info on how your resolved it?

I have a web client paho mqtt client running over websockets. My mosquitto broker sends messages between two websocket clients and between mosquitto_pub/mosquitto_pub, but mosquitto_pub messages do not get through to my websocket mqtt client.

Thanks,
Luke

John Askew

unread,
Apr 29, 2016, 8:14:50 AM4/29/16
to mq...@googlegroups.com

Not sure if it helps, but currently Mosquitto does not support libwebsockets between bridges. That bit me. I changed the secure bridge conf. to use protocol "mqtt" between bridges, but leave the clients setup using secure web sockets.

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 mqtt+uns...@googlegroups.com.

Suman Patro

unread,
May 1, 2016, 3:45:59 AM5/1/16
to mq...@googlegroups.com
Hello Luke,
Sorry , but I haven't resolved the issue yet. I studied mosquitto as a reference to understand websockets protocol  and try to build one for my own middleware. So I didn't work on mosquitto further.
Regards,
Suman Patro

Tehseen Ullah

unread,
Jul 16, 2019, 7:51:38 AM7/16/19
to MQTT
Hi sir i am using paho JavaScript library for mqtt publsih and subscribe it works perfectly with cloud mqtt and other online brokesr  but not working on my mosquito brokerjust getting this error "WebSocket connection to 'ws://10.10.1.100:1883/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT ". i also used port 9001 but not working. kindly help me
regards
Tahseen ullah

Imran Zualkernan

unread,
Jul 16, 2019, 7:57:56 AM7/16/19
to mq...@googlegroups.com
Using the wrong port.

--
To learn more about MQTT please visit http://mqtt.org
---
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 mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.

Tehseen ullah

unread,
Jul 16, 2019, 8:28:12 AM7/16/19
to mq...@googlegroups.com
Not working on 9001 port too.

Simon Walters

unread,
Jul 16, 2019, 1:21:57 PM7/16/19
to mq...@googlegroups.com
Hi
Have you got these two lines in your .conf file?
listener 9001
protocol websockets
What version of mosquitto have you and what platform is it running on BTW?
Simon

Reply all
Reply to author
Forward
0 new messages