Skip to content

Commit

Permalink
MoP accept ws connections (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
caihualin authored Apr 28, 2024
1 parent 9975b0f commit ab471c6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/using-mqtt-over-websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ client.on('message', (topic, message, packet) => {

Secure WebSocket connections can be established using the WSS protocol (WebSocket Secure), essentially a WebSocket over a TLS (previously SSL) connection. TLS is used to encrypt the data that is sent over the connection, ensuring data privacy and integrity, as well as authentication.

To use WebSocket over TLS with MQTT.js, you need to change the protocol in the broker address from `ws` to `wss`. However, you must also ensure that the broker you are connecting to supports WSS connections and that the port number is correct for WSS. For example, EMQX uses port `8084` for WSS connections by default.

To use WebSocket over TLS with MQTT.js, you need to change the protocol in the broker address from `ws` to `wss`. However, you must also ensure that the broker you are connecting to supports WSS connections and that the port number is correct for WSS. For example, MoP uses port `8084` for WSS connections by default.


Here's an example of how you might establish a secure connection:

Expand Down Expand Up @@ -211,7 +213,9 @@ const KEY = fs.readFileSync(path.join(__dirname, '/tls-key.pem'))
const CERT = fs.readFileSync(path.join(__dirname, '/tls-cert.pem'))
const TRUSTED_CA_LIST = fs.readFileSync(path.join(__dirname, '/crt.ca.cg.pem'))
const host = 'wss://broker.emqx.io:8084/mqtt'
const host = 'wss://broker.streamnative.io:8084/mqtt'
const options = {
...
key: KEY,
Expand Down Expand Up @@ -290,7 +294,9 @@ Yes, you can use MQTT over WebSocket in non-browser environments. Different prog

### Why do I need to fill in a path when connecting to MoP?

A path must be filled in when using WebSocket to connect to [MoP](https://www.emqx.io/?__hstc=3614191.cd31d14d6887cb6138feafc20e333f55.1713262331758.1713262331758.1713319978583.2&__hssc=3614191.1.1713319978583&__hsfp=4215947063). This is because EMQX follows the unified path specification of MQTT-WebSocket. This specification requires a specific path to be specified in WebSocket connections to identify and distinguish MQTT over WebSocket traffic. This path routes MQTT over WebSocket traffic to the MQTT Broker for processing.

A path must be filled in when using WebSocket to connect to [MoP](https://www.streamnative.io). This is because MoP follows the unified path specification of MQTT-WebSocket. This specification requires a specific path to be specified in WebSocket connections to identify and distinguish MQTT over WebSocket traffic. This path routes MQTT over WebSocket traffic to the MQTT Broker for processing.


In MoP, the default path for MQTT over WebSocket is `/mqtt`. This is set according to the specification. Therefore, when connecting to MoP, this path must be included in the WebSocket address to ensure the connection is correctly routed to the MQTT broker.

Expand Down

0 comments on commit ab471c6

Please sign in to comment.