mqttjs / mqtt-server

Simple API to build your own MQTT server on top of it.
Other
104 stars 31 forks source link

TypeError: client.connack is not a function #6

Open basickarl opened 4 years ago

basickarl commented 4 years ago
// Server

const mqttServer = require('mqtt-server');

const servers = mqttServer({
  mqtt: 'tcp://localhost:1883',
  mqtts: 'ssl://localhost:8883',
  mqttws: 'ws://localhost:1884',
  mqtwss: 'wss://localhost:8884'
}, function(client){
  client.connack({
    returnCode: 0
  });
});

servers.listen(function() {
  console.log('listening!');
});

// Client

const mqtt = require('mqtt')
// const client  = mqtt.connect('mqtt://test.mosquitto.org')
const client  = mqtt.connect('tcp://localhost:1883');

client.on('connect', function () {
  client.subscribe('presence', function (err) {
    if (!err) {
      client.publish('presence', 'Hello mqtt')
    }
  })
})

client.on('message', function (topic, message) {
  // message is Buffer
  console.log(message.toString())
  client.end()
})

Error:

/home/karl/dev/javascript/sandbox.js:11
  client.connack({
         ^

TypeError: client.connack is not a function
    at /home/karl/dev/javascript/sandbox.js:11:10
    at Server.<anonymous> (/home/karl/dev/javascript/node_modules/create-stream-server/index.js:13:5)
    at Server.emit (events.js:215:7)
    at TCP.onconnection (net.js:1546:8)

Seems to be broken?

zwmmm commented 3 years ago

Solved?

akiannillo commented 3 years ago

no, same problem here.

mcollina commented 3 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

akiannillo commented 3 years ago

It was a problem in the read me. Simple pullrequest #7