文档目录:


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. 自定义委托事件方法的更多相关文章

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

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  2. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:6. 设备事件上报

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  3. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:1. 连接阿里云物联网

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  4. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:7. 服务调用

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  5. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:2. IoT 客户端

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  6. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:3. 订阅Topic与响应Topic

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  7. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:4. 设备上报属性

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  8. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:5. 设置设备属性

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  9. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:4.1 上报位置信息

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

随机推荐

  1. EasyDarwin流媒体云平台:EasyCamera开源摄像机接入海康威视摄像机实时视频

    本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376/article/details/52755298 EasyCamera接收云平台实时 ...

  2. EasyDarwin开源流媒体服务器提供的TS切片/HLS直播打包库

    EasyHLS  Github:https://github.com/EasyDarwin/EasyHLS EasyHLS是什么? EasyHLS是EasyDarwin开源流媒体社区开发的一款HLS打 ...

  3. 九度OJ 1116:加减乘除 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1466 解决:902 题目描述: 根据输入的运算符对输入的整数进行简单的整数运算. 运算符只会是加+.减-.乘*.除/.求余%.阶乘!六个运 ...

  4. Hackerspace

    Hackerspace Software - HackerspaceWiki https://wiki.hackerspaces.org/Hackerspace_Software Hackerspac ...

  5. select version();desc mysql.user;

    D:\wamp64\wamp\bin\mysql\mysql5.6.17\bin>mysql -hgoDev -uroot -ppasswordWarning: Using a password ...

  6. meteor---在合并打包多个文件ZIP下载的功能

    实现多个文件边打包边下载的功能,速度还可以,本人亲测,欢迎大家来指点archiver --用NPM安装这个模块---本人文件存储在file-collection 中,可以用fs : fs.create ...

  7. Tomcat Session Clustering

    搭建 Tomcat 集群需要解决很多的问题,其中之一就是要解决 Session 共享问题.小规模集群可以使用 Tomcat 提供的 Session Clustering 来解决. For the im ...

  8. Ace(一)环境搭建

    1.下载ACE源码代码    http://www.cs.wustl.edu/~schmidt/ACE.html 2.编译源代码    2.1 进入源码包解压后的ACE_wrappers\ace目录, ...

  9. HDU2049 不容易系列之(4)考新郎 —— 错排

    题目链接:https://vjudge.net/problem/HDU-2049 不容易系列之(4)——考新郎 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  10. 编译thrift外篇-关于默认链接包-(使用mapkeeper运行leveldb成功)

    根据 https://stackoverflow.com/questions/9922949/how-to-print-the-ldlinker-search-path 使用 ldconfig -v ...