public static MqMessage Parse(byte header, uint len, MemoryStream stream) { MqMessage msg = null; switch ((MessageType)((header & 0xf0) >> 4)) { case MessageType.CONNECT: msg = new MqConnect(header, len, stream); break; case MessageType.CONNACK: msg = new MqConnack(header, len, stream); break; case MessageType.DISCONNECT: msg = new MqDisconnect(header, len, stream); break; case MessageType.PINGREQ: msg = new MqPingReq(header, len, stream); break; case MessageType.PINGRESP: msg = new MqPingResp(header, len, stream); break; case MessageType.PUBLISH: msg = new MqPublish(header, len, stream); break; case MessageType.SUBSCRIBE: msg = new MqSubscribe(header, len, stream); break; case MessageType.SUBACK: msg = new MqSuback(header, len, stream); break; case MessageType.UNSUBSCRIBE: msg = new MqUnsubscribe(header, len, stream); break; case MessageType.UNSUBACK: msg = new MqUnsuback(header, len, stream); break; case MessageType.PUBACK: case MessageType.PUBCOMP: case MessageType.PUBREC: case MessageType.PUBREL: msg = new MqMsgAck(header, len, stream); break; } return(msg); }
public static MqMessage Parse(byte header, uint len, MemoryStream stream) { MqMessage msg=null; switch((MessageType)((header & 0xf0) >> 4)) { case MessageType.CONNECT: msg=new MqConnect(header, len, stream); break; case MessageType.CONNACK: msg=new MqConnack(header, len, stream); break; case MessageType.DISCONNECT: msg=new MqDisconnect(header, len, stream); break; case MessageType.PINGREQ: msg=new MqPingReq(header, len, stream); break; case MessageType.PINGRESP: msg=new MqPingResp(header, len, stream); break; case MessageType.PUBLISH: msg=new MqPublish(header, len, stream); break; case MessageType.SUBSCRIBE: msg=new MqSubscribe(header, len, stream); break; case MessageType.SUBACK: msg=new MqSuback(header, len, stream); break; case MessageType.UNSUBSCRIBE: msg=new MqUnsubscribe(header, len, stream); break; case MessageType.UNSUBACK: msg=new MqUnsuback(header, len, stream); break; case MessageType.PUBACK: case MessageType.PUBCOMP: case MessageType.PUBREC: case MessageType.PUBREL: msg=new MqMsgAck(header, len, stream); break; } return msg; }
private void Received(MqMessage msg) { if (_pl.verbose) { Log.Debug("R {0} > {1}", this.Signature, msg); } switch (msg.MsgType) { case MessageType.CONNACK: { MqConnack cm = msg as MqConnack; if (cm.Response == MqConnack.MqttConnectionResponse.Accepted) { status = Status.Connected; _tOut.Change(KEEP_ALIVE, KEEP_ALIVE); Log.Info("Connected to {0}", Signature); foreach (var site in Sites) { site.Connected(); } } else { status = Status.NotAccepted; _tOut.Change(Timeout.Infinite, Timeout.Infinite); } } break; case MessageType.DISCONNECT: status = Status.Disconnected; _tOut.Change(3000, KEEP_ALIVE); break; case MessageType.PINGRESP: _waitPingResp = false; break; case MessageType.PUBLISH: { MqPublish pm = msg as MqPublish; if (msg.MessageID != 0) { if (msg.QualityOfService == QoS.AtLeastOnce) { this.Send(new MqMsgAck(MessageType.PUBACK, msg.MessageID)); } else if (msg.QualityOfService == QoS.ExactlyOnce) { this.Send(new MqMsgAck(MessageType.PUBREC, msg.MessageID)); } } ProccessPublishMsg(pm); } break; case MessageType.PUBACK: break; case MessageType.PUBREC: if (msg.MessageID != 0) { this.Send(new MqMsgAck(MessageType.PUBREL, msg.MessageID)); } break; case MessageType.PUBREL: if (msg.MessageID != 0) { this.Send(new MqMsgAck(MessageType.PUBCOMP, msg.MessageID)); } break; } if (_waitPingResp) { _tOut.Change(KEEP_ALIVE, KEEP_ALIVE); } }