0

在服务器上,我正在收听订阅并记录它们

mqttServ.on('subscribed', (topic, client) => {
  mqttServ.publish({
    topic: topic,
    payload: `client ${client.id} subscribed`,
    qos: 1
  }, client)
})

mqttServ.on('unsubscribed', (topic, client) => {
  console.log(
    `client ${client.id} unsuscribed from topic ${topic}`
  )
})

在客户端上,我正确地收到了第一条消息

client.on('connect', () => {
  client.subscribe('goodmorning')
})

client.on('message', (topic, payload) => {
  console.log([topic, payload].join(": "))
  client.end()
})

但我无法发送其他人......可能是因为我注意到客户正在取消订阅该主题。为什么会发生退订?

4

1 回答 1

1

删除(或注释掉)client.end() 调用 - 这将关闭客户端与代理的​​连接,这将在服务器端导致订阅被删除,因为客户端不再连接:-o

于 2016-05-23T23:08:27.903 回答