阿里云物联网 .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. 服务调用 ...
随机推荐
- yuicompressor
yui/yuicompressor: YUI Compressor https://github.com/yui/yuicompressor YUI Compressor 详细介绍 YUI ...
- 在Qt Creator中创建C++工程并使用CMake构建项目
创建完毕后,若电脑上没有安装CMake,则无法构建工程, 我用的是绿色版,官网下载地址:https://cmake.org/files/v3.10/cmake-3.10.1-win64-x64.zip ...
- 关于ActiveMQ接收端停止接收的方法
现在有一个需求: 在发送端服务器出现故障后,接收端的接收方法要停下来,关于停止接收的方法,我做了下面这些事情: // 获取 ConnectionFactory ConnectionFactory co ...
- System.IO.File类和System.IO.FileInfo类
1.System.IO.File类 ※文件create, copy,move,SetAttributes,open,exists ※由于File.Create方法默认向所有用户授予对新文件的完全读写. ...
- React-Router4按需加载
其实几种实现都是近似的,但具体上不太一样,其中有些不需要用到bundle-loader 第一种:ReactTraining/react-router 介绍的基于 webpack, babel-plug ...
- (转)windows下一分钟配置ngnix实现HLS m3u8点播
一.首先保证nginx能正常运行: 这个就是因为前面我们把nginx的目录加到了Path中,然而nginx启动时各种路径都是以当前工作目录为起始点的,这就导致了系统去“C:\User ...
- RTP/RTCP学习笔记 -- RFC 3550
The MTU of RTP package payload is (IP) - (UDP) - = 1472 #define DEFAULT_MAX_PACKET_SIZE 1200 video ...
- 基于Appium、Python的自动化测试
基于Appium.Python的自动化测试环境部署和实践 第一章 导言 1.1 编制目的 该文档为选用Appium作为移动设备原生(Native).混合(Hybrid).移动Web(Mobile ...
- jquery中attr和prop的区别—判断复选框选中状态
最近项目中需要用jquery判断input里checkbox是否被选中,发现用attr()获取不到复选框改变后的状态,最后查资料发现jQuery 1.6以后新增加了prop()方法,借用官方的一段描述 ...
- # <center>merge表不可用的问题</center>
最近碰到了个很有意思的问题,值得一写 给merge表和基础表添加索引时发生了一个问题,不管是先给merge表加索引还是基础表加索引,如果表数据量大都会导致加索引期间对merge表的查询不可用,因为使用 ...