您现在的位置是:首页 > 文章详情

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

日期:2019-06-08点击:319

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

原文链接:https://yq.aliyun.com/articles/704926
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章