内容目录
Document Directory:
CZGL.AliIoTClient has set up 7 delegated events that are triggered during different lifecycle phases of the program.
1) 7 Delegated Events
/// <summary>
/// Server Property Settings
/// </summary>
public PublishPropertyEventHandler PubPropertyEventHandler;
/// <summary>
/// Service Invocation
/// </summary>
public PublishServiceEventHandler PubServiceEventHandler;
/// <summary>
/// Triggered when receiving other Topics
/// </summary>
public PublishCommonEventHandler PubCommonEventHandler;
/// <summary>
/// When QOS=1 or 2, triggered upon subscription
/// </summary>
public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishedEventHandler PubedEventHandler;
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"><summary>
<span class="hljs-comment"><span class="hljs-doctag">/// When publishing Topic to the server
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"></summary>
<span class="hljs-keyword">public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgSubscribedEventHandler SubedEventHandler;
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"><summary>
<span class="hljs-comment"><span class="hljs-doctag">/// When publishing Topic to the server fails
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"></summary>
<span class="hljs-keyword">public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgUnsubscribedEventHandler UnSubedEventHandler;
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"><summary>
<span class="hljs-comment"><span class="hljs-doctag">/// When disconnected
<span class="hljs-comment"><span class="hljs-doctag">/// <span class="hljs-doctag"></summary>
<span class="hljs-keyword">public uPLibrary.Networking.M2Mqtt.MqttClient.ConnectionClosedEventHandler ConnectionClosedEventHandler;
Usage
public static void TestEvent(object sender, MqttMsgPublishEventArgs e)
{
{
// handle message received
string topic = e.Topic;
string message = Encoding.ASCII.GetString(e.Message);
Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("get topic message,Date: " + DateTime.Now.ToLongTimeString());
Console.WriteLine("topic: " + topic);
Console.WriteLine("get messgae :\n" + message);
}
client.PubPropertyEventHandler += TestEvent;
This is the old version of the documentation for reference.
https://www.cnblogs.com/whuanle/p/10786991.html
文章评论