MQTT in c#
I have two button in my xaml page. One is to Publish the message and other is to subscribe the topic. I have installed mosquitto as broker. In Publish button, i have written code to publish the message and in mosquitto cmd prompt, i can receive the message. In viceversa, in subscribe button, i have subscribed to one topic and in cmd prompt i am publishing message, where can i view the message in subscribe button?
Case 1:
In cmd propmt, i will subscribe to the topic,
mosquitto_sub -h 190.178.4.180 -t “test1”
private async void BtnPublish_Click(object sender, RoutedEventArgs e)
{
var message = new MqttApplicationMessage("test1", Encoding.UTF8.GetBytes("Hello"));
await client.PublishAsync(message, MqttQualityOfService.ExactlyOnce);
}
I will receive Hello in cmd propmt.
Case 2:
In cmd prompt, i will publish the message in some topic,
mosquitto_pub -h 192.168.0.180 -t test1 -m "HelloWorld"
private async void BtnSubscrbe_Click(object sender, RoutedEventArgs e)
{
await client.SubscribeAsync("test1", MqttQualityOfService.ExactlyOnce);
var message = client.MessageStream;
}
If i click the button subscribe, where will i get the published message?
Thanks in advance.