Beispiel #1
0
        public void Publish(string topic, string value, uint retain)
        {
            byte[]         payload = Encoding.ASCII.GetBytes(value);
            MqttMsgPublish msg     = MsgBuilder.BuildPublish(topic, false, (retain > 0), payload, GetNewPacketIdentifier());

            publisherManager.Publish(msg);
            FreePacketIdentifier(msg.MessageId); // this can be done automatically as long as we only publish at QoS 0
        }
        public void Publish(string topic, string value)
        {
            byte[]         payload = Encoding.ASCII.GetBytes(value);
            MqttMsgPublish msg     = MsgBuilder.BuildPublish(topic, false, (byte)this.PublishQoSLevel, Retain, payload, GetNewPacketIdentifier());

            publisherManager.Publish(msg);
            if (this.PublishQoSLevel == 0x00)
            {
                FreePacketIdentifier(msg.MessageId);
            }
        }
Beispiel #3
0
 protected void OnClientDisconnected(MqttClient client, bool withDisconnectPacket)
 {
     try
     {
         if (!withDisconnectPacket && client.WillFlag)
         {
             MqttMsgPublish publish = MsgBuilder.BuildPublish(client.WillTopic, false, client.WillQosLevel, client.WillRetain, Encoding.ASCII.GetBytes(client.WillMessage), GetNewPacketIdentifier());
             //Send(client.ClientIndex, publish.GetBytes());
             OnPacketReceived(client.ClientIndex, publish, client.IsWebSocketClient);
         }
         else if (withDisconnectPacket)
         {
             SessionManager.Destroy(client.ClientId);
             client.IsConnected = false;
         }
     }
     catch (Exception e)
     {
         CrestronLogger.WriteToLog("MQTTSERVER - OnClientDisconnected , error message : " + e.Message, 8);
         CrestronLogger.WriteToLog("MQTTSERVER - OnClientDisconnected , error STACK TRACE : " + e.StackTrace, 8);
     }
 }