[MQTT Web Client] Can't connect to broker
Web icon
Forge component by Barduino
Application Type
Traditional Web

Hi, so in trying your web demo and installing in my environment, i'm unable to connect to the broker.

I don't get an error or anything, just refuses to connect with no exceptions thrown. Can you please review the code and let me know if it can be fixed or if i'm just doing something incorrect.

The most common reason for a connection refused with and MQTT client is that it cannot reach the server itself. 

Where is the MQTT server located? Is it on a machine in your own network or on a public machine?

If it is on your own network are you using the public IP or the internal IP?  If the public IP have you setup forwarding rules on your router?

Do you have authentication on the MQTT connection?

What port is the MQTT listening on and has that been specified correctly in the connection details?

Is your MQTT setup to use https (SSL)? If so are you using a self signed certificate or a purchased certificate?

using hiveMQ. But, try their web demo and tell me if you can get it to work. I click on test connection and connect and nothing happens.

NO authentication, just their public facing MQTT server.

Hi Preston,

Open your console to see the logs.

test.mosquitto.org is a public mqtt broker and very slow, increase your time out for the connection to complete.


IT's working now, but whenever i click on publish message, i get the message but it says undefined, undefined. This is on mine and the example TRY that's hosted here.

If you are encountering issues with an MQTT Web Client and it's unable to connect to the broker, here are some general troubleshooting steps you can follow to diagnose and potentially resolve the problem:

1. **Check Broker Availability:**

   - Ensure that the MQTT broker you are trying to connect to is running and reachable. Verify the broker's IP address or hostname and port number.

2. **Network Connectivity:**

   - Confirm that your device or server where the MQTT client is running has proper network connectivity. Check for any firewall rules or network restrictions that might be blocking the MQTT traffic.

3. **Client Configuration:**

   - Double-check your MQTT client's configuration, including the broker's address, port number, and authentication credentials (username and password). Make sure they are correctly specified in your client code.

4. **Library or Framework Issues:**

   - If you are using an MQTT library or framework, ensure that it is up to date and compatible with the MQTT broker version you are using. Check for any known issues or updates related to the library or framework.

5. **Error Handling:**

   - Review your code for any error handling mechanisms. MQTT client libraries typically provide error callbacks or logs. Check if there are any error messages or exceptions that might give clues about the issue.

6. **Broker Logs:**

   - Check the logs on the MQTT broker side for any error messages or indications of failed connection attempts. This can help diagnose issues from the broker's perspective.

7. **Firewall and Security Policies:**

   - If you are running the MQTT broker in a secure environment, make sure that your client's IP or hostname is allowed to connect according to the broker's security policies.

8. **TLS/SSL Configuration (if using):**

   - If you are using TLS/SSL for secure MQTT connections, ensure that the client has the correct SSL/TLS certificates and configurations set up.

9. **Test with MQTT Testing Tools:**

   - You can use MQTT testing tools like MQTT Explorer, MQTT.fx, or MQTTBox to verify your MQTT broker's connectivity independently from your client code. This can help isolate whether the issue is with the client or the broker.

10. **Firewall and Router Settings:**

    - Check for firewall or router settings that might be blocking MQTT traffic. Ensure that the MQTT broker's port is properly forwarded if necessary.

11. **Browser Security Restrictions (for web-based clients):**

    - If you're using a web-based MQTT client, be aware that modern browsers may impose security restrictions on WebSocket connections. Ensure that your WebSocket connection settings comply with the browser's security policies.

12. **Broker Authentication and Authorization:**

    - Verify that the MQTT broker has the necessary authentication and authorization settings configured and that your client credentials match these settings.

By following these steps and carefully reviewing your MQTT client configuration and code, you should be able to identify and resolve the issue preventing your MQTT Web Client from connecting to the broker.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.