/// <summary> /// Constructs a PublishArrivedArgs object /// </summary> /// <param name="topic">Source of message</param> /// <param name="payload">Message body</param> /// <param name="retained">Whether or not the message is retained</param> public PublishArrivedArgs(string topic, MqttPayload payload, bool retained, QoS qos) { _topic = topic; _payload = payload; _retained = retained; _qos = qos; }
// TODO: Add a constructor containing WillTopic and WillMessage public MqttConnectMessage( string clientID, string username, string password, ushort keepAlive, string willTopic, byte[] willPayload, QoS willQos, bool willRetained, bool cleanStart ) : base(MessageType.CONNECT) { SetConnectVariableHeaderCommon(clientID, username, password, keepAlive); _containsWill = true; _willTopic = willTopic; _willPayload = willPayload; _connectFlags = (byte)( 0x04 | // LWT enabled (willRetained ? 0x20 : 0) | // LWT is retained? (cleanStart ? 0x02 : 0) | // Clean Start (_containsPassword ? 0x40 : 0) | (_containsUsername ? 0x80 : 0) | ((byte)willQos) << 3 // LWT QoS ); base.variableHeaderLength += ( _willTopic.Length + _willPayload.Length + 4 ); }
public async Task <PostResult> PostMessage(string topic, byte[] data, QoS qos) { FrameBuilder bld = new FrameBuilder(); bld.WriteByte((byte)(qos == QoS.BestEffort ? 0x00 : 0x01)); // ToDo: Generate Frame Number to receive ACK. currentPacketId++; bld.WriteArray(BitConverter.GetBytes(currentPacketId)); bld.WriteString(topic); bld.WriteMultiByte(data.Length); bld.WriteArray(data); if (qos == QoS.GuaranteedDelivery) { if (!syncSendInProcess.WaitOne(3000)) { return(PostResult.DispatchError); } waitForPacketId = currentPacketId; } socket.Send(bld.Build(FrameType.ChannelEvent)); if (qos == QoS.GuaranteedDelivery) { var replyReceived = waitQosEvent.WaitOne(3000); syncSendInProcess.ReleaseMutex(); return(replyReceived ? PostResult.Delivered : PostResult.DeliveryError); } return(PostResult.Dispatched); }
public void subscribe(String topic, QoS qos, Callback cb) //throws IOException { SubscribeMessage msg = new SubscribeMessage(topic, qos, this); msg.setMessageId(getNextMessageId()); sendCallbackMessage(msg, cb); }
private void timerQuality_Elapsed(object sender, ElapsedEventArgs e) { try { if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new EventHandler <ElapsedEventArgs>(this.timerQuality_Elapsed), sender, new object[] { e }); return; } if (this.AVSession != null && this.AVSession.IsActive) { QoS qos = this.AVSession.GetVideoQualityInfo(); if (qos != null) { this.labelQuality.Content = string.Format("Quality: {0}%", (uint)(qos.getQavg() * 100)); if (this.qosWindow != null && this.qosWindow.IsVisible) { this.qosWindow.Info = qos; } } } } catch (Exception ex) { LOG.Error(ex); } }
public Subscription Add(string topic, QoS qos) { var s = new Subscription(topic, qos); Add(s); return(s); }
public MqttParcel(string topic, byte[] payload, QoS qos, bool retained) { this.topic = topic; this.payload = new MqttPayload(payload, 0); this.qos = qos; this.retained = retained; }
public MqttParcel(string topic, MqttPayload payload, QoS qos, bool retained) { this.topic = topic; this.payload = payload; this.qos = qos; this.retained = retained; }
private void ConstructHeader(byte header) { msgType = (MessageType)((header & 0xf0) >> 4); isDuplicate = (header & 0x08) != 0; msgQos = (QoS)((header & 0x06) >> 1); isRetained = (header & 0x01) != 0; }
public MqttPublishMessage(string topic, MqttPayload payload,bool retained, QoS qos) { _topic = topic; _payload = payload; _retained = retained; _qos = qos; }
private static async Task PublishMessages(IQueueOf<string> queue, QoS qos, int passes) { var watch = new Stopwatch(); var counters = new List<long>(); for (var i = 1; i <= passes; i++) { Write("Publishing 1000 messages ({0} QoS), pass {1}/{2} -> ", qos.ToString(), i, passes); watch.Restart(); for (var j = 0; j < 1000; j++) { await queue.PublishAsync(j.ToString(), qos: qos); } watch.Stop(); counters.Add(watch.ElapsedMilliseconds); WriteLine(watch.ElapsedMilliseconds); } var average = counters.Sum() / passes; WriteLine("Average time (ms): {0}", average); WriteLine("Average rate (msg/s): {0}", Math.Truncate(decimal.Divide(1000, average) * 1000)); WriteLine(); }
public void publish(String topic, byte[] message, QoS qos, Callback cb) //throws IOException { PublishMessage msg = new PublishMessage(topic, message, qos, this); msg.setMessageId(getNextMessageId()); sendCallbackMessage(msg, cb); }
public void Connect(string willTopic, QoS willQoS, MqttPayload willMsg, bool willRetain, bool cleanStart) { _keepAlive = 60; DoConnect(new MqttConnectMessage( _clientID, _username, _password, _keepAlive, willTopic, willMsg.TrimmedBuffer, willQoS, willRetain, cleanStart )); }
public MqttParcel(string topic, byte[] payload, QoS qos, bool retained) { this.topic = topic; this.payload = new MqttPayload(payload,0); this.qos = qos; this.retained = retained; }
public MqttParcel(string topic, MqttPayload payload, QoS qos, bool retained ) { this.topic = topic; this.payload = payload; this.qos = qos; this.retained = retained; }
public SubscribeMessage(String topic, QoS topicQos, MqttConnection conn) : base(MessageType.SUBSCRIBE, conn) { setQos(QoS.AT_LEAST_ONCE); topics.Add(topic); topicQoSs.Add(topicQos); }
public Header(MessageType type, bool retain, QoS qos, bool dup) { this.type = type; this.retain = retain; this.qos = qos; this.dup = dup; }
public Header(byte flags) { retain = (flags & 1) > 0; qos = (QoS)((Convert.ToInt32(flags) & 0x6) >> 1); dup = (flags & 8) > 0; type = (MessageType)((Convert.ToInt32(flags) >> 4) & 0xF); }
public PublishMessage(String topic, byte[] data, QoS qos, MqttConnection conn) : base(MessageType.PUBLISH, conn) { this.topic = topic; this.data = data; setQos(qos); }
public void setWill(String willTopic, String will, QoS willQoS, bool retainWill) { this.willTopic = willTopic; this.will = will; this.willQoS = willQoS; this.retainWill = retainWill; }
public MsSuback(QoS qualityOfService, ushort topicId, ushort msgId, MsReturnCode code) : base(MsMessageType.SUBACK) { _qualityOfService = qualityOfService; _topicId = topicId; _msgId = msgId; _retCode = code; }
/// <summary>Creates an MqttMessage from a data stream</summary> /// <param name="header">The first byte of the fixed header of the message</param> /// <param name="len">Variable header length</param> /// <param name="str">Input stream</param> protected MqMessage(byte header, uint len, Stream str) //-V3117 { this.MsgType = (MessageType)((header & 0xf0) >> 4); this.Duplicate = (header & 0x08) != 0; this.QualityOfService = (QoS)((header & 0x06) >> 1); this.Retained = (header & 0x01) != 0; variableHeaderLength = len; }
protected MqMessage(MessageType msgType) { this.MsgType = msgType; this.Duplicate = false; this.QualityOfService = QoS.AtMostOnce; this.Retained = false; this.MessageID = 0; }
private void addQoS(QoS qos) { if (grantedQoSs == null) { grantedQoSs = new List <QoS>(); } grantedQoSs.Add(qos); }
/// <summary> /// Creates a new context. /// </summary> /// <param name="version">The version of MQTT.</param> /// <param name="isEmitter">Whether this is our special implementation.</param> /// <param name="id">The client id specified in the MQTT connect packet.</param> public MqttContext(MqttProtocolVersion version, QoS qos, bool isEmitter, string id, string username) { this.Version = version; this.QoS = qos; this.IsEmitter = isEmitter; this.ClientId = id; this.Username = username; }
public Message(MessageType type, QoS qos, bool retain, bool duplicateDelivery) { FixedHeader = new FixedHeader(); FixedHeader.MessageType = type; FixedHeader.QoS = qos; FixedHeader.Retain = retain; FixedHeader.DuplicateDelivery = duplicateDelivery; }
public void Publish(string topic, string data, QoS qos, bool retain) { //var encoded = Encoding.ASCII.GetBytes(data); //Publish(topic, data, qos, retain); var encoded = Encoding.UTF8.GetBytes(data); Publish(topic, encoded, qos, retain); TracingDebug("Send Publish: topic=" + topic + ",content=" + data); }
/// <summary> /// Recycles the packet. /// </summary> public override void Recycle() { this.Origin = null; this.Lifetime = PacketLifetime.Automatic; this.ProtocolVersion = MqttProtocolVersion.Unknown; this.DupFlag = false; this.QoS = QoS.AtMostOnce; this.Retain = false; }
private static void Mqtt_MessageReceived(string topic, QoS qos, byte[] payload) { Debug.WriteLine("<-" + System.Text.Encoding.UTF8.GetString(payload)); MensajeRecibido(null, new Tools.MensajeRecibido() { Mensaje = System.Text.Encoding.UTF8.GetString(payload), Topico = topic }); }
public override void setQos(QoS qos) { if (qos != QoS.AT_LEAST_ONCE) { //throw new IllegalArgumentException( // "SUBSCRIBE is always using QoS-level AT LEAST ONCE. Requested level: " // + qos); } base.setQos(qos); }
public Subscription(string topic, QoS qos) { Validate .Begin() .IsNotNullOrEmpty(topic) .Check(); TopicName = topic; QoS = qos; }
public PublishMessage(bool duplicate, bool retain, QoS qos, String topic, byte[] message, short?packetId) : base(MessageType.Publish, (packetId.HasValue ? 2: 0) + GetSize(topic) + GetSize(message, false), (byte)((duplicate ? 0x08 : 0) | (retain ? 0x01 : 0) | (byte)qos << 1)) { Duplicate = duplicate; Retain = retain; QoS = qos; Topic = topic; payload = message; PacketId = packetId; }
public override PostResult DispatchMessage(string topic, byte[] data, QoS qos) { Console.WriteLine("A message was posted in: " + topic); Console.WriteLine(Encoding.UTF8.GetString(data)); var res = base.DispatchMessage(topic, data, qos); base.DispatchMessage("SomeChannel", Encoding.UTF8.GetBytes("This is yet another message."), QoS.BestEffort); return(res); }
public void publish(String topic, byte[][] message, QoS qos, Callback[] cb) //throws IOException { PublishMessage[] messagesToPublish = new PublishMessage[cb.Length]; for (int i = 0; i < message.Length; i++) { messagesToPublish[i] = new PublishMessage(topic, message[i], qos, this); messagesToPublish[i].setMessageId(getNextMessageId()); } sendCallbackMessage(messagesToPublish, cb); }
public MqttPublishMessage( ushort id, string topic, byte[] payload, QoS qos, bool retained ) : base(MessageType.PUBLISH) { _topic = topic; _payload = payload; _messageID = id; base.msgQos = qos; base.isRetained = retained; base.variableHeaderLength = 2 + GetUTF8StringLength(topic) + // Topic + length (qos == QoS.BestEfforts ? 0 : 2) + // Message ID for QoS > 0 payload.Length; // Message Payload }
public MqttExtendedackMessage(ulong msgID, string topic, byte[] payload, QoS qos, int ttl, string apn_json) : base(MessageType.EXTENDEDACK, 8, msgID) { _commondId = 7; base._messageID = msgID; base.msgQos = QoS.AtLeastOnce; MemoryStream pay = new MemoryStream(); pay.WriteByte(0); WriteToStream(pay, topic); pay.WriteByte(1); WriteToStream(pay, payload); if (ttl > 0) { pay.WriteByte(3); WriteToStream(pay, ttl.ToString()); } string[] qos2str = {"0", "1", "2"}; pay.WriteByte(6); WriteToStream(pay, qos2str[(int)qos]); if (apn_json != null) { pay.WriteByte(7); WriteToStream(pay, apn_json); } byte[] paybytes = pay.ToArray(); if (paybytes.Length <= 65535) { _leftLength = (ushort)paybytes.Length; _payload = paybytes; } else throw new ArgumentOutOfRangeException("payload length is longer then 65535."); base.variableHeaderLength = 11 + _payload.Length; }
public ulong Publish2Alias(string alias, MqttPayload payload, QoS qos, int ttl, string apn_json) { return Publish2(",yta/" + alias, payload, qos, ttl, apn_json); }
public ulong Publish2(string topic, MqttPayload payload, QoS qos, int ttl, string apn_json) { if (manager.IsConnected) { ulong messID = MessageID; manager.SendMessage(new MqttExtendedackMessage(messID, topic, payload.TrimmedBuffer, qos, ttl, apn_json)); return messID; } else { throw new MqttNotConnectedException("You need to connect to a broker before trying to Publish"); } }
public int Subscribe(string topic, QoS qos) { return Subscribe(new Subscription(topic, qos)); }
public int Publish(string topic, MqttPayload payload, QoS qos, bool retained) { if (manager.IsConnected) { ushort messID = MessageID; manager.SendMessage(new MqttPublishMessage(messID, topic, payload.TrimmedBuffer, qos, retained)); return messID; } else { throw new MqttNotConnectedException("You need to connect to a broker before trying to Publish"); } }
public void Add(QoS gQoS) { grantedQos.Add(gQoS); }
public ulong PublishToAlias(string alias, MqttPayload payload, QoS qos, bool retained) { return Publish(",yta/" + alias, payload, qos, retained); }
public ulong Publish(string topic, MqttPayload payload, QoS qos, bool retained) { if (manager.IsConnected) { // Reset the PINGREQ timer as this publish will reset the server's counter if (keepAliveTimer != null) { int kmillis = 1000 * _keepAlive; keepAliveTimer.Change(kmillis, kmillis); } ulong messID = MessageID; manager.SendMessage(new MqttPublishMessage(messID, topic, payload.TrimmedBuffer, qos, retained)); return messID; } else { throw new MqttNotConnectedException("You need to connect to a broker before trying to Publish"); } }
public Subscription(string topic, QoS qos) { _topic = topic; _qos = qos; }
protected MqMessage(MessageType msgType) { this.MsgType = msgType; this.Duplicate=false; this.QualityOfService=QoS.AtMostOnce; this.Retained=false; this.MessageID=0; }
public MsSuback(QoS qualityOfService, ushort topicId, ushort msgId, MsReturnCode code) : base(MsMessageType.SUBACK) { _qualityOfService=qualityOfService; _topicId=topicId; _msgId=msgId; _retCode=code; }
public int Subscribe(string topic, QoS qos) { throw new NotImplementedException(); }
public void Add(string topic, QoS sQoS) { _list.Add(new KeyValuePair<string,QoS>(topic, sQoS)); }
public static void MqttPublish(this IXSocketController controller, string topic, object obj, QoS qosLevel = QoS.FireAndForget, bool retain = false) { var data = Encoding.UTF8.GetBytes(controller.JsonSerializer.SerializeToString(obj)); Composable.GetExport<IMqttBridge>().PublishToMqttClients(new MqttMsgPublish(topic, data, false, (byte)qosLevel, retain)); }
public static void MqttPublish(this IXSocketController controller, string topic, byte[] data, QoS qosLevel = QoS.FireAndForget, bool retain = false) { Composable.GetExport<IMqttBridge>().PublishToMqttClients(new MqttMsgPublish(topic, data, false, (byte)qosLevel, retain)); }
public void Subscribe(string topic, QoS sQoS) { MqSubscribe msg=new MqSubscribe(); msg.Add(topic, sQoS); Send(msg); }
public void Connect(string willTopic, QoS willQoS, MqttPayload willMsg, bool willRetain) { DoConnect(new MqttConnectMessage( _clientID, _keepAlive, willTopic, willMsg.TrimmedBuffer, willQoS, willRetain, false )); }
public void Connect(string username, string password,string willTopic, QoS willQoS, MqttPayload willMsg, bool willRetain, bool cleanStart) { DoConnect(new MqttConnectMessage( _clientID, _keepAlive,username,password, willTopic, willMsg.TrimmedBuffer, willQoS, willRetain, cleanStart )); }
/// <summary>Creates an MqttMessage from a data stream</summary> /// <param name="header">The first byte of the fixed header of the message</param> /// <param name="len">Variable header length</param> /// <param name="str">Input stream</param> protected MqMessage(byte header, uint len, Stream str) { this.MsgType = (MessageType)((header & 0xf0) >> 4); this.Duplicate = (header & 0x08) != 0; this.QualityOfService = (QoS)((header & 0x06)>>1); this.Retained = (header & 0x01) != 0; variableHeaderLength = len; }
public MsPublish(Topic val, ushort topicId, QoS qualityOfService) : base(MsMessageType.PUBLISH) { this.IsRequest=qualityOfService!=QoS.AtMostOnce; this.qualityOfService=qualityOfService; this.TopicId=topicId; this._val=val; if(MsDevice.PredefinedTopics.ContainsValue(topicId) && (_val==null || MsDevice.PredefinedTopics.ContainsKey(_val.name) || MsDevice.PredefinedTopics.ContainsKey(".cfg/"+_val.name))) { this.topicIdType=TopicIdType.PreDefined; } }