示例#1
0
        /// <summary>
        /// 当收到发布消息
        /// </summary>
        /// <param name="dataPackage"></param>
        protected virtual void OnPublish(MQTTDataPackage dataPackage)
        {
            PublishDataPackage publishDataPackage = new PublishDataPackage(dataPackage);
            var result = OnPublish(publishDataPackage);

            if (dataPackage.QoS > 0)
            {
                var package = new MQTTDataPackage()
                {
                    MessageType = MessageType.PublishAck, Data = new byte[3] {
                        (byte)(publishDataPackage.Identifier >> 8), (byte)(publishDataPackage.Identifier & 255), 0
                    }
                };
                if (dataPackage.QoS == 1)
                {
                    if (!result.Success)
                    {
                        package.Data[2] = 1;
                    }
                    SendPackage(package);
                }
            }
        }
示例#2
0
 /// <summary>
 /// 当客户发布消息。
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 protected virtual Result OnPublish(PublishDataPackage message)
 {
     WriteLog($"客户端{message.ClientId}发布消息{message.Topic},QoS{message.QoS}。内容:{message.Text}");
     return(true);
 }
示例#3
0
 /// <summary>
 /// 发布消息。
 /// </summary>
 /// <param name="message">要发布的消息。</param>
 /// <returns></returns>
 public virtual Result Publish(PublishDataPackage message)
 {
     message.Identifier = ++Identifier;
     this.SendPackage(message);//目前不校验,qos 直接发送
     return(true);
 }