Example #1
0
        /// <summary>
        /// Set properties on the request that are based on properties on this object
        /// </summary>
        /// <param name="request">Request we are going to send</param>
        /// <param name="endpoint">Endpoint to use sending the message</param>
        /// <returns>Request passed in</returns>
        protected Request Prepare(Request request, IEndPoint endpoint)
        {
            request.Type          = _type;
            request.URI           = Uri;
            request.OscoapContext = OscoapContext;

            if (UriPath != null)
            {
                request.UriPath = UriPath;
            }

            if (UriQuery != null)
            {
                request.UriQuery = UriQuery;
            }

            if (Blockwise != 0)
            {
                request.SetBlock2(BlockOption.EncodeSZX(Blockwise), false, 0);
            }

            if (endpoint != null)
            {
                request.EndPoint = endpoint;
            }

            return(request);
        }
Example #2
0
        public void TestServer()
        {
            // We do not test for block 0 because the client is currently unable to
            // know if the user attempts to just retrieve block 0 or if he wants to
            // do early block negotiation with a specific size but actually wants to
            // retrieve all blocks.

            Int32[]  blockOrder   = { 2, 1, 3 };
            String[] expectations =
            {
                RESPONSE_PAYLOAD.Substring(32 /* until the end */),
                RESPONSE_PAYLOAD.Substring(16, 16),
                null // block is out of bounds
            };

            for (Int32 i = 0; i < blockOrder.Length; i++)
            {
                Int32 num = blockOrder[i];
                Console.WriteLine("Request block number " + num);
                Int32   szx     = BlockOption.EncodeSZX(16);
                Request request = Request.NewGet();
                request.URI = new Uri("coap://localhost:" + _serverPort + "/" + TARGET);
                request.SetBlock2(szx, false, num);
                request.Send();
                Response response = request.WaitForResponse(1000);
                Assert.IsNotNull(response);
                Assert.AreEqual(expectations[i], response.PayloadString);
                Assert.IsTrue(response.HasOption(OptionType.Block2));
                Assert.AreEqual(num, response.Block2.NUM);
                Assert.AreEqual(szx, response.Block2.SZX);
            }
        }
Example #3
0
        /// <summary>
        /// Converts a BlockOption with the specified parameters to a byte array and
        /// back and checks that the result is the same as the original.
        /// </summary>
        private void TestCombined(Int32 szx, Boolean m, Int32 num)
        {
            BlockOption block = new BlockOption(OptionType.Block1, num, szx, m);
            BlockOption copy  = new BlockOption(OptionType.Block1);

            copy.RawValue = block.RawValue;
            Assert.AreEqual(block.SZX, copy.SZX);
            Assert.AreEqual(block.M, copy.M);
            Assert.AreEqual(block.NUM, copy.NUM);
        }
Example #4
0
 /// <summary>
 /// Helper function that creates a BlockOption with the specified parameters
 /// and serializes them to a byte array.
 /// </summary>
 private Byte[] ToBytes(Int32 szx, Boolean m, Int32 num)
 {
     Byte[] bytes = new BlockOption(OptionType.Block1, num, szx, m).RawValue;
     return(bytes);
 }