阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:8. 委托事件

  1. 云栖社区>
  2. 博客>
  3. 正文

阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:8. 委托事件

燕小范 2019-06-09 21:07:06 浏览235
展开阅读全文

CZGL.AliIoTClient 里设置了 7 个委托事件,在程序的不不同生命周期触发。

1)7个委托事件

        /// <summary>
        /// 服务器属性设置
        /// </summary>
        public PublishPropertyEventHandler PubPropertyEventHandler;
        /// <summary>
        /// 服务调用
        /// </summary>
        public PublishServiceEventHandler PubServiceEventHandler;
        /// <summary>
        /// 收到其它Topic时触发
        /// </summary>
        public PublishCommonEventHandler PubCommonEventHandler;
        /// <summary>
        /// 当 QOS=1或2时,收到订阅触发
        /// </summary>
        public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishedEventHandler PubedEventHandler;

        /// <summary>
        /// 向服务器发布 Topic 时
        /// </summary>
        public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgSubscribedEventHandler SubedEventHandler;

        /// <summary>
        /// 向服务器发布 Topic 失败时
        /// </summary>
        public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgUnsubscribedEventHandler UnSubedEventHandler;


        /// <summary>
        /// 断开连接时
        /// </summary>
        public uPLibrary.Networking.M2Mqtt.MqttClient.ConnectionClosedEventHandler ConnectionClosedEventHandler;

使用方法

    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;

这里是旧版本的文档,可以参考一下。
https://www.cnblogs.com/whuanle/p/10786991.html

网友评论

登录后评论
0/500
评论
燕小范
+ 关注