# (SOLVED) How to set HiveMQ broker to connect using mqtt:// instead of ws://

**URL:** <https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697>\
**Category:** Uncategorized\
**Created:** [August 25, 2021, 9:58am UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697 "2021-08-25T09:58:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshabuggi](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@harshabuggi](https://community.hivemq.com/u/harshabuggi)\
**Post date:** [August 25, 2021, 9:58am UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/1 "2021-08-25T09:58:42Z")

</div>

Hi,

Could you please provide configuration information to connect to HiveMQ broker using “mqtt://” protocol instead of "ws://.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [August 25, 2021, 10:38am UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/2 "2021-08-25T10:38:41Z")

</div>

Hi @harshabuggi,

You can find the description on how to use Websockets with HiveMQ in our [documentation](https://www.hivemq.com/docs/hivemq/4.6/user-guide/listeners.html#ws-listener).

```auto
<hivemq xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <listeners>
      <websocket-listener>
          <port>8000</port>
          <bind-address>0.0.0.0</bind-address>
          <path>/mqtt</path>
          <name>my-websocket-listener</name>
          <subprotocols>
              <subprotocol>mqttv3.1</subprotocol>
              <subprotocol>mqtt</subprotocol>
          </subprotocols>
          <allow-extensions>true</allow-extensions>
      </websocket-listener>
       ...
   </listeners>
    ...
</hivemq>

```

Kind regards,  
Florian

---

<div class="post-metadata">

**Author:** ![harshabuggi](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@harshabuggi](https://community.hivemq.com/u/harshabuggi)\
**Post date:** [August 25, 2021, 11:21am UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/3 "2021-08-25T11:21:49Z")

</div>

Hi @hivemq-support,

Thank you for your response. My websocket listener is configured like this

\< websocket-listener \>  
\< port \>${PORT}\< /por t\>  
\< bind-address \>0.0.0.0\< /bind-address \>  
\< path \>/mqtt\< /path \>  
\< name \>my-websocket-listener\< /name \>  
\< subprotocols \>  
\< subprotocol \>mqttv3.1\< /subprotocol \>  
\< subprotocol \>mqtt\< /subprotocol \>  
\< /subprotocols \>  
\< allow-extensions \>true\< /allow-extensions \>  
\< /websocket-listener \>

But I am not able to connect to the broker using connection string

“mqtt://\< hostname \>:\< portnumber \>/mqtt”

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [August 25, 2021, 11:28am UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/4 "2021-08-25T11:28:55Z")

</div>

You need to use `ws://` instead of `mqtt://` when connecting over websocket.  
It’s not possible to use MQTT when connecting over a browser.  
See this [blog post](https://www.hivemq.com/blog/mqtt-essentials-special-mqtt-over-websockets/)

Regards,  
Florian

---

<div class="post-metadata">

**Author:** ![harshabuggi](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@harshabuggi](https://community.hivemq.com/u/harshabuggi)\
**Post date:** [August 25, 2021, 12:00pm UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/5 "2021-08-25T12:00:03Z")

</div>

Hi @hivemq-support,

I need to connect using a NodeJS mqtt client and not with a browser. How can I modify the config.xml to enable connecting with “mqtt://”

i was able to deploy a cluster using HiveMQ cloud and access using “mqtts://”. But the hostname is too long and I cannot use it for my application. So I am trying to find the configuration to enable this in HiveMQ docker container.

Appreciate your help.

Thank you.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [August 25, 2021, 12:05pm UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/6 "2021-08-25T12:05:07Z")

</div>

Hi @harshabuggi,

Sorry about the confusion then.  
Simply use a TCP listener then.

```auto
<?xml version="1.0"?>
<hivemq xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    ...
    <listeners>
        ...
        <tcp-listener>
            <port>1883</port>
            <bind-address>0.0.0.0</bind-address>
            <name>my-tcp-listener</name>
        </tcp-listener>
    </listeners>
    ...
</hivemq>

```

You can try to connect to the [HiveMQ public broker](https://www.hivemq.com/public-mqtt-broker/) for testing.

`mqtt://broker.hivemq.com:1883` is likely the correct URL for your application.

Best,  
Florian

---

<div class="post-metadata">

**Author:** ![harshabuggi](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@harshabuggi](https://community.hivemq.com/u/harshabuggi)\
**Post date:** [August 25, 2021, 12:18pm UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/7 "2021-08-25T12:18:13Z")

</div>

Hi @hivemq-support,

I currently cannot use a public broker. I am not able to connect to the tcp port using the connection string

“mqtt//:\< my hostname \>:\< port \>”

Getting response “connect ECONNREFUSED 127.0.0.1:7883” (7883 is the port I have set for tcp listener).

Please advice.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [August 25, 2021, 12:27pm UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/8 "2021-08-25T12:27:52Z")

</div>

Maybe this blog can help: [Using the Node.js MQTT Client-Starting Guide](http://www.steves-internet-guide.com/using-node-mqtt-client/)  
Or the official documentation: [GitHub - mqttjs/MQTT.js: The MQTT client for Node.js and the browser](https://github.com/mqttjs/MQTT.js/#example)

Kind regards,  
Florian

---

<div class="post-metadata">

**Author:** ![harshabuggi](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@harshabuggi](https://community.hivemq.com/u/harshabuggi)\
**Post date:** [August 25, 2021, 12:30pm UTC](https://community.hivemq.com/t/solved-how-to-set-hivemq-broker-to-connect-using-mqtt-instead-of-ws/697/9 "2021-08-25T12:30:04Z")

</div>

HI @hivemq-support,

This is working. I had not started the container with the right port mapping.

Thank you so much.

Regards,  
Harsha
