I try to connect to my mosquitto broker.
The problem im facing, as soon as the "connect" package is writen, the tcp socket is closed.
I guess this happens because the package is invalid/the broker expect something else?
Code i used for testing:
const net = require("net");
const mqtt = require("mqtt-packet");
const parser = mqtt.parser({
protocolVersion: 4
});
const socket = net.Socket();
socket.on("close", () => {
console.log("connection closed");
});
socket.on("data", (data) => {
console.log(">", data);
parser.once('packet', packet => {
console.log(packet)
});
parser.parse(data);
});
socket.on("connect", () => {
console.log("Connected to tcp://open-haus.lan:1883");
let data = mqtt.generate({
cmd: 'connect',
protocolId: 'MQTT', // Or 'MQIsdp' in MQTT 3.1 and 5.0
protocolVersion: 4, // Or 3 in MQTT 3.1, or 5 in MQTT 5.0
clean: true, // Can also be false
clientId: 'my-device-test-node',
//keepalive: 0, // Seconds which can be any positive number, with 0 as the default setting
will: {
topic: '#',
payload: Buffer.from('dead'), // Payloads are buffers
}
});
socket.write(data, () => {
console.log("connect has writen", data)
});
});
socket.connect(1883, "open-haus.lan");
I try to connect to my mosquitto broker. The problem im facing, as soon as the "connect" package is writen, the tcp socket is closed. I guess this happens because the package is invalid/the broker expect something else?
Code i used for testing:
Output:
The "data" event on the tcp socket isnt even fired.
As seen in this graphic, after the tcp socket is established, a connect packet is send to the broker:
I dont get anything back.