Websocket connection to mosquitto broker fail

Hi Team.

First all. After trying out the management certer for mosquitto, I have to say it’s really nice. Especially the dynamic security plugin control operation is really cool.

Actually, I got a question regarding the websocket connection to mosquitto broker. I got two copies of mosquitto installed on my server (Ubuntu 18.04 LTS). One is the official eclipse mosquitto 2.0.11 and the other is cedalo’s.

I also built a cellphone app with paho javascript client. The cellphone app communicates to broker with websocket.

However, when working with the eclipse mosquitto, my cellphone app can communicate with the broker through websocket no problem. But when switch to the cedalo, even though the log says brokier is listening to websocket. My cellphone app just cannot connect to cedalo’s broker.

And when checking the log, there is absolutely nothing showing my app’s attempt to connect the broker.

Sorry if this is a silly question. But is the websocket available in cedalo’s mosquitto 2.0 broker? Thanks! :smiley:

Hi Shawn_leo,

Yes, websockets is available. The broker you download on the Cedalo page should be the same that you get at the Eclipse Foundation page / mosquitto.org page. Differences start, when you go for premium features like stream processing, high availability etc. But since you do not have a paid subscription with us, then the broker you downloaded should be barebone Mosquitto 2.0. So, from your answer:

  • web sockets is enabled in the conf file of the “cedalo” mosquitto?
  • Are you sure that you have the right URL in from your app to the “cedalo” mosquitto?
  • necessary ports are open?
  • clients/ Groups/roles are set up in the same way like on your eclipse copy of the broker?

Regards,
Stefan

Another thing that @roger.light just brought up: Are the necessary ports on Docker properly configured?

Hi Stefan,

Thanks a lot for your thorough explaination. I am very glad to hear that cedalo’s mosquitto supports websocket. Next I will try to find out what mistake I am making here.

And thanks for your instructions about finding the causes of my problem. The following is what I am having here.

For web socket enable in the conf file. I belive it’s done. This is because I could see message “mosquitto_1 | 1628516882: Opening websockets listen socket on port 8080.” when starting cedalo’s mosquitto. And trust me, I have been using websocket to communicate with mosquitto broker for years. So setting up the conf that has websocket enabled is out of the question.

For url settings in my app, as I mentioned in my message I have two copies of mosquitto on the same server. When I use the eclipse mosquitto, I could use my app connecting to the broker via websocket. But when switching to cedalo’s mosquitto, I cannot use my app connecting to broker via websocket. Same server same url just the mosquitto is diffrent. So I believe url is not the cause.

For clients/groups/roles, I tested cedalo mosquitto with mqtt.fx. Everything works great. Actually, I find cedalo’s mosquitto being better. I actually encountered an issue using eclipse mosquitto. The problem is I cannot use mosquitto_ctrl to create client with clientid associated to it.

I submitted this issue to the eclipse mosquitto’s github. The issue can be seen in the following link.

https://github.com/eclipse/mosquitto/issues/2273

And the above issue is one of the major resons I am using cedalo’s mosquitto instead of eclipse’s.

You guys are the experts and if you could give me some advice regarding the above issue that will be awesome! If not, that’s fine. I know I am not the only one having the above issue.

Sorry I am kinda carried away here. In short, I tested cedalo’s mosquitto with mqtt.fx and everything is ok. So client/role/group is not a problem. The problem I am experiencing is just when I am using websocket to connect to cedalo’s mosquitto.

Anyhow, I will keep on trying to find out the reason why. Will let you know what mistake I made if I find it.

Thanks! :smiley:

it could be it. I will check it out. Thanks for your help!

You are welcome! If you still don’t get it running then please let us know. Also if you found the culprit then please also make a short post since this helps others in the community maybe doing the same thing. Thanks!

Yes. I configured the docker port as you instructed and now my cedalo websocket works! Since I am really green to docker so I did not even know I needed to configure the ports in docker.

Here is what I did. I modified the docker-compose.yml. Under the services section, I saw ports - 1880:1880. And I just added the following below it.

- 8080:8080

All in all, now my docker-compose.yml looks like the following:

version: "3.6"
services:
  mosquitto:
    image: eclipse-mosquitto:2-openssl
    ports:
      - 1883:1883
      - 8080:8080  # This like is what I added
    networks:
      - cedalo-platform
    # ...The rest of the file is omitted...

I am not sure if what I did is appropriate for configuring the docker port. It works anyway. If you think my modification above is correct, I will make a short post that maybe some help to others. If you have better way doing it, please let me know.

Again, thanks!

1 Like

@shawn_leo: The page https://docs.docker.com/compose/networking/ explains pretty well what these - host port number: container port number lines do: If one of your docker containers that is part of the compose is trying to reach another container in the compose then the SECOND port is used. If an external application is trying to reach the docker container then the IP of docker + the FIRST port number needs to be used. Hence you are by that mapping the beforehand only internally reachable websockets port to an externally reachable port. In your special case the port numbers are identical, but this does not have to be the case (see example on the page I referenced above). I would gues from your post that you did the right thing.

@Tizian.Cedalo: Can you have a look here, if this is all correct? Or if you have further input?

1 Like

You are right, allocating ports in docker is important.
I also think, that this was the reason for the problems! :slight_smile:

Thanks for your thorough explaination. I will definately checkout the page you recomended. And thanks for your help!

Yes. Absolutely.

1 Like