简体   繁体   English

如何在WebSocket服务器中获取MQTT客户端的主题

[英]How to get topic of mqtt client in websocket server

I am trying to get topic of mqtt client, i searched in google, i couldn't find right one. 我正在尝试获取mqtt客户端的主题,我在Google中进行了搜索,找不到合适的主题。

for example, from mqtt client, publish one message,consider server topic is 'topicOfServer' and client topic is 'topicOfClient'. 例如,从mqtt客户端发布一条消息,请考虑服务器主题为“ topicOfServer”,而客户端主题为“ topicOfClient”。

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

server will get 'hi server' message. 服务器将收到“ hi server”消息。 but how do server knows that message came from which client ex: 'topicOfClient' 但是服务器如何知道该消息来自哪个客户端,例如:'topicOfClient'

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. 主题只是任何MQTT客户端可以向其发送消息的“地址”,它们不以任何方式由任何客户端拥有。
  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. 除非发送方在消息有效负载中的某处编码该信息,否则无法确定哪个MQTT客户端从另一个MQTT客户端发布了任何消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM