Skip to content

subscribed client doesn't receive the message from broker #22

@nick1008

Description

@nick1008

node version: 8.11.0
working on windows 7.

The client is successfully subscribed.

The broker receives the publish from client A but doesn't forward it to client B

`server.on('connection', function (stream) {
let conn = mqttConn(stream)

// conn connected
conn.on('connect', function (packet) {
	console.log(conn.options);
  	// acknowledge the connect packet
  	conn.connack({ returnCode: 0 });
	})

conn.on('publish', function (packet) {
	times++;
	packet2send = packet;
	console.log(packet);
	conn.pubrec({ messageId: packet.messageId });
	conn.on('pubrel', function (packet) {
		console.log(packet);
		conn.pubcomp({ messageId: packet.messageId });
		stream.setTimeout(10000)
		stream.on('timeout', function () {
	  		conn.publish({
				retain: false,
				qos: 2,
				dup: false,
				length: 14,
				topic: 'hello',
				payload: 'world',
				messageId: 1
			});
	  		conn.on('pubrec', function (packet) {
				console.log('aa' + packet);
	  			conn.pubrel({ messageId: packet.messageId });
				console.log(packet);
				conn.on('pubcomp', function (packet) {
					console.log('aa' + packet);
					console.log(packet);
				});
			})
		});
	})
})

// conn subscribed
conn.on('subscribe', function (packet) {
	console.log(packet);
// send a suback with messageId and granted QoS level
	conn.suback({ granted: [packet.qos], messageId: messageId })
})

// timeout idle streams after 5 minutes
//stream.setTimeout(1000 * 60 * 5)

// connection error handling
conn.on('close', function (packet) { conn.destroy() 
	console.log('close ' + packet);})
conn.on('error', function (packet) { conn.destroy() 
	console.log('error ' + packet);})
conn.on('disconnect', function (packet) { conn.destroy() 
	console.log('disconnect' + packet);})

})`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions