Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.createConnection is not a function #8

Open
MajorMayer opened this issue Dec 10, 2022 · 3 comments
Open

net.createConnection is not a function #8

MajorMayer opened this issue Dec 10, 2022 · 3 comments

Comments

@MajorMayer
Copy link

当协议是 mqtt:https:// 的时候 会出现这个错误 Uncaught (in promise) TypeError: net.createConnection is not a function

@tommy44458
Copy link
Owner

Hi @MajorMayer,

It seems that there is no way to connect directly to the broker via TCP on the browser. It would be best if you used WebSocket (ws:https://, wss:https://) as your protocol.
See here: https://www.hivemq.com/blog/mqtt-essentials-special-mqtt-over-websockets/

@jskim82
Copy link

jskim82 commented Feb 10, 2023

Hi @tommy44458
I also got the same error
image
image
image

Is it not available in nuxt3?

@tommy44458
Copy link
Owner

tommy44458 commented Feb 10, 2023

Hi @jskim82, (sorry that I tagged the wrong name the first time

Maybe you can try another way to connect with your broker:

React or Typescript instance

// src/app.tsx
// protocol = 'wss', 'ws', 'mqtt', ...
// host = ip or domain
// port = 8083, 1883, ...
import { useMQTT } from 'mqtt-vue-hook'
const mqttHook = useMQTT()

mqttHook.connect(`${protocol}:https://${host}:${port}`, {
    clean: false,
    keepalive: 60,
    clientId: `mqtt_client_${Math.random().toString(16).substring(2, 10)}`,
    connectTimeout: 4000,
})

Also, I think your broker need to open a port for web socket connections. Then, your protocol should be ‘ws’ and port should be ‘your broker’s listening port for web socket’.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants