示例#1
0
        /// <summary>
        /// Returns a response to the caller.
        /// </summary>
        /// <param name="Code">CoAP message code.</param>
        /// <param name="Payload">Optional payload.</param>
        /// <param name="Block2Nr">Block index to transmit.</param>
        /// <param name="BlockSize">Block size, in case the <paramref name="Payload"/> needs to be divided into blocks.</param>
        /// <param name="Options">Optional options.</param>
        internal void Respond(CoapCode Code, byte[] Payload, int Block2Nr, int BlockSize,
                              params CoapOption[] Options)
        {
            this.endpoint.Transmit(this.client, this.remoteEndpoint, this.client.IsEncrypted,
                                   this.responded ? (ushort?)null : this.request.MessageId,
                                   this.ResponseType, Code, this.request.Token, false, Payload, Block2Nr, BlockSize,
                                   this.resource, null, null, null, null, CoapEndpoint.Merge(Options, this.additionalResponseOptions));

            this.responded = true;
        }
示例#2
0
        /// <summary>
        /// Returns a response to the caller.
        /// </summary>
        /// <param name="Code">CoAP message code.</param>
        /// <param name="Payload">Optional payload to be encoded.</param>
        /// <param name="BlockSize">Block size, in case the <paramref name="Payload"/> needs to be divided into blocks.</param>
        /// <param name="Options">Optional options.</param>
        public void Respond(CoapCode Code, object Payload, int BlockSize, params CoapOption[] Options)
        {
            byte[] Data = CoapEndpoint.Encode(Payload, out int ContentFormat);

            if (!CoapEndpoint.HasOption(Options, 12))
            {
                Options = CoapEndpoint.Merge(Options, new CoapOptionContentFormat((ulong)ContentFormat));
            }

            this.Respond(Code, Data, BlockSize, Options);
        }