阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:9. 自定义委托事件方法
文档目录:
CZGL.AliIoTClient 有7个委托事件,设置了默认的方法。 你可以通过下面的方法使用默认的方法绑定到委托事件中。
public void UseDefaultEventHandler()
1)默认的方法
收到服务器下发属性设置时:
public void Default_PubPropertyEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到服务器调用服务命令时:
public void Default_PubServiceEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到普通Topic、上传数据的响应等其它情况:
public void Default_PubCommonEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到服务器QOS为1的推送
public void Default_PubedEventHandler(object sender,
MqttMsgPublishedEventArgs e)
当向服务器发送消息成功时:
public void Default_SubedEventHandler(object sender,
MqttMsgSubscribedEventArgs e)
向服务器推送消息失败时:
public void Default_UnSubedEventHandler(object sender,
MqttMsgUnsubscribedEventArgs e)
连接断开时
public void Default_ConnectionClosedEventHandler(object sender,
System.EventArgs e)
2)方法的写法
不同的委托参数不同,有好几种类型,参考笔者的方法使用参数。
/// 一般的推送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_PubCommonEventHandler(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);
}
/// <summary>
/// 收到属性设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_PubPropertyEventHandler(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);
}
/// <summary>
/// 收到服务调用
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_PubServiceEventHandler(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);
}
/// <summary>
/// 收到服务器QOS为1的推送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_PubedEventHandler(object sender, MqttMsgPublishedEventArgs e)
{
Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("published,Date: " + DateTime.Now.ToLongTimeString());
Console.WriteLine("MessageId: " + e.MessageId + " Is Published: " + e.IsPublished);
}
/// <summary>
/// 向服务器推送成功
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e)
{
Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("Sub topic,Date: " + DateTime.Now.ToLongTimeString());
Console.WriteLine("MessageId: " + e.MessageId);
Console.WriteLine("List of granted QOS Levels: " + Encoding.UTF8.GetString(e.GrantedQoSLevels));
}
/// <summary>
/// 推送失败
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e)
{
Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("Sub topic error,Date: " + DateTime.Now.ToLongTimeString());
Console.WriteLine("MessageId: " + e.MessageId);
}
/// <summary>
/// 连接发生异常,断网等
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Default_ConnectionClosedEventHandler(object sender, EventArgs e)
{
Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("Connect Closed error,Date: " + DateTime.Now.ToLongTimeString());
}
阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:9. 自定义委托事件方法的更多相关文章
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:8. 委托事件
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:6. 设备事件上报
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:1. 连接阿里云物联网
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:7. 服务调用
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:2. IoT 客户端
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:3. 订阅Topic与响应Topic
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:4. 设备上报属性
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:5. 设置设备属性
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:4.1 上报位置信息
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
随机推荐
- SAM4E单片机之旅——9、UART与MCK之MAINCK
为得到更高的带宽,需要使用更高的波特率.UART波特率的计算已经介绍过了,现在就尝试下调整外设的时钟频率.可以有多种方法调整外设时钟(MCK)的频率,这里先介绍先主要时钟(MAINCK)的设置,其中包 ...
- Extjs form 表单的 submit
说明:extjs form表单的提交方式是多种多样的,本文只是介绍其中的一种方法,本文介绍的方法可能不是完美的,但是对于一般的应用应该是没有问题的. 本文包括的主要内容有:form面板设计.f ...
- Markov and Chebyshev Inequalities and the Weak Law of Large Numbers
https://www.math.wustl.edu/~russw/f10.math493/chebyshev.pdf http://www.tkiryl.com/Probability/Chapte ...
- Android笔记之DrawerLayout的基本使用
效果图 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- 【C++基础学习】数据封装、构造函数
第一部分 类和对象 内存中按照用途被划分的五个区:栈区.堆区.全局区.常量区.代码区栈区由系统来进行控制,无论是内存的分配还是回收都不需要程序员关心堆区由new分配内存,使用完成之后必须使用delet ...
- Windows程序设计(1)——Win32运行原理(二)
创建进程 1 进程和线程 2 应用程序的启动过程 3 CreateProcess函数 4 实例 3 创建进程 3.1 进程和线程 进程通常被定义为一个存在运行的程序的实例.进程是一个正在运行的程序,它 ...
- LuNamp和LuManager的目录结构
/|---- etc/|-------- my.cnf #mysql配置文件|-------- ipfw.conf #ipfw防火墙的配置文件(仅FreeBSD)|---- home/|------- ...
- pypi指定下载源
pip install -i http://pypi.douban.com/simple/ scipy==0.19.0
- html页面表格导出到excel总结
转载:http://www.cnblogs.com/liuguanghai/archive/2012/12/31/2840262.html <table id="tableExcel& ...
- TCP连接过程
TCP建立连接与释放连接 最近复习准备<计算机网络>考试,感觉TCP协议建立连接与释放连接这两个过程比较重要,所以把自己理解的部分写下来. 1.建立连接:(三次握手) (1)客户端发 ...