Enabling websockets support in packaged mosquitto 1.4.7 - mqtt

How is websocket support enabled in mosquitto 1.4.7 when it's installed via a package manager (apt-get install mosquitto)? I see there is support for it, but I cannot determine how to enable it (and set the port) in configuration. There is an article that seems to indicate it can be enabled when built from source (https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/).
Is building from source the only option to enable websocket support?

Assuming support is compiled into the build you have then adding the following to the mosquitto.conf should work
listener 9001
protocol websockets
This will start a websocket listener on port 9001
If the build you have doesn't have websocket support then the following error will be printed to the console:
Error: Websockets support not available.

Related

Paho C++ MQTT Client unable to connect to Mosquitto on Ubuntu Docker Image (Python Client Works)

I am facing this issue for a couple of days and I am unable to reproduce it outside the Ubuntu Docker container.
Please refer to this simplified diagram of my architecture:
As you can see, I have everything running inside the Docker container.
This is not the typical issue of not being able to connect to inside the container, the whole application runs on the local network of the Docker container.
The Ubuntu Image is the official one with just some packages installed so that everything works (nothing too fancy, just python3 and some c++ tools).
It is running Mosquitto 2.0.15 with the following configuration:
listener 1883
protocol mqtt
allow_anonymous true
log_dest file /home/user/mosquitto.log
So, in summary, I am running an unsecured MQTT broker in the default port 1883. I also added a log file in an attempt to debug what is going on.
On my Python Client, the connection is made in the simplest way possible:
...
self.mqtt_client = mqtt.Client(client_id="Client Id")
self.mqtt_client.connect("localhost", 1883, 6000)
...
self.mqtt_client.loop_start()
...
This Client is able to connect to the broker with no issue at all.
Subscribe and Publish works perfectly too!
On my C++ Client, I try to keep it simple as well:
...
mqtt::async_client MQTTClient("tcp://localhost:1883", "Another Client Id");
MQTTClient.connect()->wait();
...
Yet, this Client fails every attempt to connect to the broker:
terminate called after throwing an instance of 'mqtt::exception'
what(): MQTT error [-1]: TCP/TLS connect failure
Aborted (core dumped)
Although it looks like a SSL/TLS error, this is actually the generic error for when the MQTT broker is not found (If I stop the broker on my local machine I get the same error).
Checking the MQTT broker logs (verbose ON), it does not record anything regarding the attempt to connect from C++ Client:
1672874968: mosquitto version 2.0.15 starting
1672874968: Config loaded from /etc/mosquitto/conf.d/default.conf.
1672874968: Opening ipv4 listen socket on port 1883.
1672874968: mosquitto version 2.0.15 running
(I do get log messages when connecting with Python Client)
On my own Linux machine I am unable to reproduce this issue. Both clients work fine.
I am using the same configuration for the Mosquitto broker and the Clients are exactly the same.
Already tried to play with the IP used to connect to the broker (localhost/127.0.0.1/0.0.0.0) and using different ports, the result is the same.
It is weird that the Python Client can connect with no issue at all.
At this point, I am fairly confident that the issue must be something Docker-specific and how it handles TCP sockets. But I am unable to find anything helpful online.
I can easily check that the port is open:
lsof -i -P -n | grep :1883
mosquitto 56 user 5u IPv4 1633274841 0t0 TCP 127.0.0.1:1883 (LISTEN)
Any ideas what is going on? Or debug tools ideas?
Thanks in advance!
I have tried:
Playing with IP and port of the broker;
Stating the preferable MQTT version (tried with every version);
Run Client with strace and try to find something unusual;
Verify if I am running the exact same Client as my Linux machine;
I finally found out what my issue was.
I had a HTTP proxy configured and Paho C will automatically use this proxy.
It is detecting by checking if "http_proxy" environment variable is set.
My solution was simply unset this variable:
unset http_proxy
Interestingly, the Python MQTT client does not have this behavior.
And for that reason, it worked perfectly!

Mosquitto server hosted on Digital ocean not making remote connections with android and Eclipse Paho Javascript Clients

I hosted Mosquitto MQTT broker on Ubuntu in Digital Ocean Cloud droplet. It's domain name is instrux.live and IP of the domain is 192.34.63.138. I publish and subscribe messages from two terminal windows and it worked fine.
When I tried to connect it with the android using Paho MQTT android client it could not connect. I also checked its connection with the MyMQTT android application and it did not connect. After making sure the android code has not any error, I again checked its connection with the Eclipse Paho Javascript client on eclipse.org website and it did not connect. Now, I have realized there might be something missing or wrong in my broker configuration which is not allowing it to get connected with other clients remotely. I have also opened firewall for ports 1883 for Android client and 8083 for the Javascript client and still it is not connecting.Here is mosquitto configuration file:
allow_anonymous true
password_file /etc/mosquitto/passwd
listener 1883
protocol mqtt
listener 8083
protocol websockets
Since the error is "Connection Refused" rather than a timeout I suspect that you have not configured the firewall to allow inbound traffic on port 8083.
You may need to do this both on the machine it's self and in Digital Ocean's console.

Trying to setup Neo4j 3.2.0 in ubuntu server

I am trying to setup Neo4j version 3.2.0 in the ubuntu server 14.04.2 LTS
Downloaded the tar and extracted the folder, edited the config file to update the port to 4444, for the time being disabled the bolt connector, listen_address to 0.0.0.0 for the http connector, authentication also disabled just to get started.
bolt connector is updated with the port 7687 even though it is disabled as i was trying earlier with it enabled.
Now when i try to connect to the http://serverip:4444/browser, it says Database access not available and shows me the login screen with host prefilled bolt://serverip:7687
Also I see this error on the console window
WebSocket connection to ws://serverip:7687/
failed: Error in connection establishment:
net::ERR_CONNECTION_TIMED_OUT
Dont understand the issues here, please help me out. I am not sure why is it trying to do a WS to the port assigned to the bolt, when it is disabled at the first place.
Regards
There's a bit of juggling going on for HTTP connector support between the browser and the driver being used, a handoff which isn't complete, and the state of things is the browser is only supporting bolt connections right now.
The javascript bolt driver is being upgraded to handle http connections, I think, so you may need to wait until the next 3.2.x release to use the http connector again.
I think this issue should be tracking it.

Enabling mosquitto over websocket in windows

I have built mosquitto on Visual Studio with websockets enabled, using Cmake to generate the project files. I used libwebsockets-1.4 .
I ran this broker with a websocket listener, and as following image it started listening on port 8000 through websockets.
Now I used the PAHO websocket client and tried to connect to the broker
client = new Paho.MQTT.Client("localhost", 8000, "abc123");
client.connect({onSuccess:onConnect});
function onConnect() {
console.log("onConnect");
}
Even with verbose logging i see nothing in the broker logs. And in the browser console I get
WebSocket connection to 'ws://localhost:8000/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
After that I tried it with the test.mosquitto.org:8080 , and it got connected with no issue.
PS : I then tried mosquitto 1.4.7 and libwebsocket 1.6 combination which resulted in following build errors, please suggest me a fix.
Next attempt was with mosquitto 1.4.2 and libwebsockets 1.4 , had no issue building mosquitto with it. When i used a regular tcp client it worked fine, when a connect message from a websocket client was sent mosquitto.exe crashes.
What may have gone wrong and how can I overcome this issue? Anyone who had successfully deployed mosquitto with websocket support on windows please help out.
I managed to get mosquitto built with websocket support by using mosquitto 1.4.7 and libwebsockets 1.5 without a problem.

How to start dart web app on server on default port

I just install dart on my server Ubuntu 12.04. I started on mydomain.com:8080/ and "hello word" displayed. But for real web app I need to run on address mydomain.com (without :8080). When I try to set port 80 on dart script it failed because apache already run on port 80. Here is my current dart script: https://www.dartlang.org/dart-by-example/#http-server So how can I do it?
If you want your Dart app to bind to port 80 you have to stop Apache or bind Apache to another port.
Another solution is to make Dart run by Apache http://news.dartlang.org/2012/05/run-dart-in-apache-web-server.html (didn't read or try myself)
You could use Apache as a proxy (via mod_proxy) to your Dart based webserver. It allows you to have both the power of Apache and Dart on the same device. I haven't used this approach in combination with Dart yet, but I use it with Java applications on Tomcat. Here is a simple Tomcat related example (scroll down to "Configure mod_proxy"). It should be easy to apply that to a Dart based server.
But that might not work with Websockets. The good thing about Websockets is that they aren't limited by the same origin policy, so you can run your Websocket applications on another port.

Resources