Android Question MQTT Chat with Auto Discovery - Sending a message to a specific one client

Lakhtin_V

Active Member
Licensed User
Longtime User
In the chat example, messages from one client are shown to all clients. How can you send a message to only one specific client if you know his name.
 

Num3

Active Member
Licensed User
Longtime User
You can make the client subscribe to a specific topic.

For example:
B4X:
mqtt.Subscribe("msgQ/secret_hash_for_private_msgs/#", 0)

Then make the private messages go into that topic
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
You can make the client subscribe to a specific topic.

For example:
B4X:
mqtt.Subscribe("msgQ/secret_hash_for_private_msgs/#", 0)

Then make the private messages go into that topic
Is this method only suitable for the chat example? Or can this line be used anyway? This is permission for private messages, but it is not clear how to aim at the right client. How to publish a message to a specific client?
Example:
client.Publish2("NickCleent", CreateMesage, 0, False)
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
How to publish a message to a specific client?
You can do it the way Num3 told, in your example:

mqtt.Subscribe("NickCleent", 0)

Make sure the nickname is unique, and then it will act as the secret hash Num3 said.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
In the chat example, messages from one client are shown to all clients. How can you send a message to only one specific client if you know his name.
Mqtt it just is a messaging protocol, how to send message to a specific client it depends on how you design your chat room,if everyone has an unique ID, you can publish message using id as topic and the client subscirble it by id
 
Upvote 0
Top