Пример #1
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="mType">The message type</param>
        /// <param name="mCode">The message code</param>
        /// <param name="coapReq">The CoAPRequest against which this response is being constructed</param>
        public CoAPResponse(byte mType, byte mCode, CoAPRequest coapReq)
        {
            if (mType == CoAPMessageType.CON)
            {
                throw new ArgumentException("A response message must be of type ACK or RST or NON");
            }

            if (!CoAPMessageCode.DoesMessageCodeRepresentAResponse(mCode))
            {
                throw new ArgumentException("The message code can only be used for a request");
            }

            this.Version = new CoAPVersion();

            this.MessageType       = new CoAPMessageType();
            this.MessageType.Value = mType;

            this.Code = new CoAPMessageCode();
            if (!this.Code.IsValid(mCode))
            {
                throw new ArgumentException("Response code invalid");
            }
            this.Code.Value = mCode;
            this.ID         = new CoAPMessageID(coapReq.ID.Value);
            this.Token      = new CoAPToken(coapReq.Token.Value);
            //TOCHECK::this.Options = new CoAPHeaderOptions(coapReq.Options);
            this.Options = new CoAPHeaderOptions();
            //Other needed parameters
            this.RemoteSender = coapReq.RemoteSender;
        }
Пример #2
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="mType">The message type</param>
        /// <param name="mCode">The message code</param>
        /// <param name="id">The message Id</param>
        public CoAPResponse(byte mType, byte mCode, UInt16 id)
        {
            if (mType == CoAPMessageType.CON)
            {
                throw new ArgumentException("A response message must be of type ACK or RST or NON");
            }

            if (!CoAPMessageCode.DoesMessageCodeRepresentAResponse(mCode))
            {
                throw new ArgumentException("The message code can only be used for a request");
            }

            this.Version = new CoAPVersion();

            this.MessageType       = new CoAPMessageType();
            this.MessageType.Value = mType;

            this.Code = new CoAPMessageCode();
            if (!this.Code.IsValid(mCode))
            {
                throw new ArgumentException("Invalid message code in request");
            }
            this.Code.Value = mCode;
            this.ID         = new CoAPMessageID(id);
            this.Options    = new CoAPHeaderOptions();
        }