0

I am trying to get topic of mqtt client, i searched in google, i couldn't find right one.

for example, from mqtt client, publish one message,consider server topic is 'topicOfServer' and client topic is 'topicOfClient'.

client.publish('topicOfServer','hi server');

server will get 'hi server' message. but how do server knows that message came from which client ex: 'topicOfClient'

raj peer
  • 694
  • 6
  • 13

1 Answers1

0

You seam to be confusing a couple of things here

  1. Topics are just "addresses" that any MQTT client can send a message to, they are not owned in any way by any client.
  2. There is no way to determine which MQTT client published any message from another MQTT client unless the sender encodes that information somewhere in the message payload.
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • thanks for response.. I have 2 clients, two clients sending different messages. then how do server knows from which client particular message came.. – raj peer Mar 08 '17 at 12:00
  • You don't unless you include some identifier in the message payload – hardillb Mar 08 '17 at 12:14
  • thank you. can you please tell me how to include identifiers in the message payload – raj peer Mar 08 '17 at 12:17
  • No, MQTT message payloads are free form byte arrays, you can send anything you want in them, I have no idea what you are currently sending so can't advise how to change that – hardillb Mar 08 '17 at 12:19