public void Publish(string topic, byte[] data, QoSLevel qosLevel, bool retain, ushort packetId) { if (packetId == 0) { throw new ArgumentException(nameof(packetId)); } var publish = new MqttPacket(PacketType.Publish) { LastWillTopic = topic, Data = data, IsDuplicated = false, LastWillQosLevel = qosLevel, LastWillRetain = retain, PacketId = packetId }; var enqueue = this.PushPacketToQueue(publish, PacketDirection.ToServer); if (!enqueue) { throw new Exception("Packet full."); } }
private void ReadFixedHeader(byte fixedHeader) { _retain = (fixedHeader & 0x01) != 0; _qosLevel = (QoSLevel)((fixedHeader & 0x06) >> 1); _dup = (fixedHeader & 0x08) != 0; _messageType = (MqttMessageType)((fixedHeader & 0xf0) >> 4); }
public MqttMessage(MqttMessageType messageType, QoSLevel qosLevel, bool retain, bool dup) { _qosLevel = qosLevel; _messageType = messageType; _retain = retain; _dup = dup; }
public Will(QoSLevel qos, bool retain, string topic, EncodedDataField message) { QoS = qos; Retain = retain; Topic = topic; Message = message; }
public MqttConnectMessage(string clientId, bool cleanSession, ushort keepAliveTimer, string willTopic, byte[] willMessage, QoSLevel willQos, bool willRetain) : this(clientId, cleanSession, keepAliveTimer) { _willTopic = willTopic; if (!string.IsNullOrEmpty(_willTopic)) { _willQos = willQos; _willRetain = willRetain; _willMessage = willMessage; _hasWill = true; } }
private void QoSTest(QoSLevel Level) { ManualResetEvent Received = new ManualResetEvent(false); ManualResetEvent Delivered = new ManualResetEvent(false); this.client2.OnNormalMessage += (sender, e) => Received.Set(); this.client1.SendMessage(Level, MessageType.Normal, this.client2.FullJID, string.Empty, "Hello", string.Empty, "en", string.Empty, string.Empty, (sender, e) => Delivered.Set(), null); Assert.IsTrue(Delivered.WaitOne(10000), "Message not delivered properly."); Assert.IsTrue(Received.WaitOne(10000), "Message not received properly."); }
private MqttQualityOfServiceLevel ConvertQosLevel(QoSLevel qosLvl) { switch (qosLvl) { case QoSLevel.AtMostOnce: return(MqttQualityOfServiceLevel.AtMostOnce); case QoSLevel.AtLeastOnce: return(MqttQualityOfServiceLevel.AtLeastOnce); case QoSLevel.ExactlyOnce: return(MqttQualityOfServiceLevel.ExactlyOnce); default: throw new ArgumentOutOfRangeException(nameof(qosLvl), qosLvl, null); } }
public MqttConnectionInfo(string clientId, string host, int port) { if (string.IsNullOrEmpty(clientId)) throw new ArgumentNullException("clientId"); if (string.IsNullOrEmpty(host)) throw new ArgumentNullException("host"); if (port <= 0) throw new ArgumentException("Invalid port"); _host = host; _port = port; _clientId = clientId; _willQoS = QoSLevel.AtMostOnce; _keepAliveInterval = 10; }
public MqttConnectionInfo(string clientId, string host, int port) { if (string.IsNullOrEmpty(clientId)) { throw new ArgumentNullException("clientId"); } if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } if (port <= 0) { throw new ArgumentException("Invalid port"); } _host = host; _port = port; _clientId = clientId; _willQoS = QoSLevel.AtMostOnce; _keepAliveInterval = 10; }
private static void ConvertToQualityOfServiceLevel(MqttApplicationMessageBuilder builder, QoSLevel qos) { switch (qos) { case QoSLevel.AtMostOnce: builder.WithAtMostOnceQoS(); break; case QoSLevel.AtLeastOnce: builder.WithAtLeastOnceQoS(); break; case QoSLevel.ExactlyOnce: builder.WithExactlyOnceQoS(); break; default: throw new ArgumentOutOfRangeException(nameof(qos), qos, null); } }
internal static ControlPacketFlags GetPublishFlags(bool duplicate, QoSLevel qos, bool retain) { return(new ControlPacketFlags(duplicate, qos, retain)); }
protected ControlPacketFlags(bool duplicate, QoSLevel qos, bool retain) { Duplicate = duplicate; QoS = qos; Retain = retain; }
public static FixedHeader CreatePublishHeader(bool duplicate, QoSLevel qos, bool retain, UInt32 remainingLength) { return(new FixedHeader(ControlPacketType.PUBLISH, ControlPacketFlags.GetPublishFlags(duplicate, qos, retain), remainingLength)); }