Пример #1
0
 private void MyMqttBroker_OnBrokerStarted(object source, MqttCustomBrokerEventArgs e)
 {
     ToogleStartButtonThreadSafe(false);
     WriteMainTextBoxThreadSafe("Broker Started" + Environment.NewLine + "Process: " + e.ProcessName + Environment.NewLine + "PID: " + e.ProcessId + Environment.NewLine);
     Task.Factory.StartNew(() =>
     {
         _watcherClient = new MqttClient("127.0.0.1");
         _watcherClient.MqttMsgPublishReceived += _watcherClient_MqttMsgPublishReceived;
         String clientid = Guid.NewGuid().ToString();
         _watcherClient.Connect(clientid, Settings.Default.BrokerUsername, Settings.Default.BrokerPassword);
         _watcherClient.Subscribe(new[] { "+/+/+" }, new[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
         _watcherClient.Subscribe(new[] { "+/+" }, new[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
         _watcherClient.Subscribe(new[] { "+" }, new[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
         _watcherClient.Subscribe(new[] { "+/+/+/+" }, new[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
         _watcherClient.Publish("INFO", Encoding.UTF8.GetBytes("Watcher: Listening to All Topics"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
     });
 }
Пример #2
0
 private void MyMqttBroker_OnBrokerExited(object source, MqttCustomBrokerEventArgs e)
 {
     ToogleStartButtonThreadSafe(true);
     WriteMainTextBoxThreadSafe("Broker Stopped" + Environment.NewLine);
 }