Hello, the issue #170 is still alive in version 1.4.10. The address is still ignored. Used Debian binary mosquitto_1.4.10-0mosquitto4_amd64.deb from http://repo.mosquitto.org/, running on vServer with multiple network interfaces.
For simple test you can use 127.0.0.1. Here are minimal steps to reproduce it:
echo "listener 1234 127.0.0.1" >/etc/mosquitto-websocket.conf
echo "protocol websockets" >>/etc/mosquitto-websocket.conf
mosquitto -v -c /etc/mosquitto-websocket.conf
1475840402: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1475840402: Config loaded from /etc/mosquitto-websocket.conf.
1475840402: Opening websockets listen socket on port 1234.
Open a second terminal to check binded interfaces:
netstat -anp | grep mosquitto
tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 21900/mosquitto
Compairing with protocol mqtt, there it is working:
echo "listener 1234 127.0.0.1" >/etc/mosquitto-mqtt.conf
echo "protocol mqtt" >>/etc/mosquitto-mqtt.conf
mosquitto -v -c /etc/mosquitto-mqtt.conf
1475840579: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1475840579: Config loaded from /etc/mosquitto-mqtt.conf.
1475840579: Opening ipv4 listen socket on port 1234.
Check opened ports in second terminal:
netstat -anp | grep mosquitto
tcp 0 0 127.0.0.1:1234 0.0.0.0:* LISTEN 21905/mosquitto
With sugestion from minghuadev in #170:
So the part
[ip address/host name]can actually take[ip address/host name/iface name]for websockets protocol.
I found, that interface name is working.
echo "listener 1234 lo" >/tmp/mosquitto-websocket.conf
echo "protocol websockets" >>/tmp/mosquitto-websocket.conf
mosquitto -v -c /tmp/mosquitto-websocket.conf
1476774954: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1476774954: Config loaded from /tmp/mosquitto-websocket.conf.
1476774954: Opening websockets listen socket on port 1234.
Check on other terminal:
netstat -anp | grep mosquitto
tcp 0 0 127.0.0.1:1234 0.0.0.0:* LISTEN 26509/mosquitto
Next check on an interface with alias address.
echo "listener 1234 venet0:1" >/tmp/mosquitto-websocket.conf
echo "protocol websockets" >>/tmp/mosquitto-websocket.conf
mosquitto -v -c /tmp/mosquitto-websocket.conf
1476775075: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1476775075: Config loaded from /tmp/mosquitto-websocket.conf.
1476775075: Opening websockets listen socket on port 1234.
That is also working :+1:
netstat -anp | grep mosquitto
tcp 0 0 123.123.101.100:1234 0.0.0.0:* LISTEN 26513/mosquitto
Hi, @HenryNe, I checked out trunk which basically is 1.4.10 plus two commits. It still works for me.
I have the libwebsockets and mosquitto in the directory:
-rwxr-xr-x 1 144492 May 28 16:12 libwebsockets.so.8
-rwxr-xr-x 1 440970 Oct 24 22:54 mosquitto
and the config file contains:
listener 9008 127.0.0.1
protocol websockets
launch mosquitto on websocket:
$ LD_LIBRARY_PATH=. ./mosquitto -v -c mosquitto.conf
1477377030: mosquitto version 1.4.10 (build date 2016-10-25 05:50:08+0000) starting
1477377030: Config loaded from mosquitto.conf.
1477377030: Opening websockets listen socket on port 9008.
check port and address:
$ netstat -nap | grep mosquitto
tcp 0 0 127.0.0.1:9008 0.0.0.0:* LISTEN 20879/./mosquitto
if you check the commit by @ralight under #170, the port is directly assigned to an info->iface, that is simply passed to libwebsocket. I also verified it with the libwebsockets author back in may. see https://github.com/warmcat/libwebsockets/issues/538, it should work.
so what's the version of your libwebsockets?
My libwebsocket is older. It is version 1.2.2-1 from year 2013. This is system default and no newer version exist in Debian 8.2 repositories.
$ dpkg -l '*libwebsockets*' | grep libwebsockets
ii libwebsockets3:amd64 1.2.2-1 amd64 lightweight C websockets library
$ mosquitto -h | head -n 1
mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100)
$ ldd /usr/sbin/mosquitto | grep libwebsockets
libwebsockets.so.3 => /usr/lib/x86_64-linux-gnu/libwebsockets.so.3 (0x00007f8990675000)
$ ls -lH /usr/lib/x86_64-linux-gnu/libwebsockets.so.3
-rw-r--r-- 1 root root 72000 May 13 2013 /usr/lib/x86_64-linux-gnu/libwebsockets.so.3
According to the debian package tracking the 1.7.3-1 is going to be auto-removed on Nov 25 for the next release. Not sure how that would get pass that, and make into into jessie repo. The source stable version by warmcat is 1.7.9, debian is only on 1.7.3-1 that looks quite old.
To set the binding address for the websocket listener require a more recent version of libwebsocket. It was fixed in 2014 (https://github.com/warmcat/libwebsockets/issues/116).
Note that using interface name is not guaranteed to works. It works for websocket because libwebsockets allow them and mosquitto pass the value as-is. This may change in the future.
Closing as nothing can be done on Mosquitto side, it's libwebsocket that need an update.
Most helpful comment
With sugestion from minghuadev in #170:
I found, that interface name is working.
Check on other terminal:
Next check on an interface with alias address.
That is also working :+1: