示例#1
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);
            }
        }
示例#2
0
        protected Request Prepare(Request request, IEndPoint endpoint)
        {
            request.Type = _type;
            request.URI  = _uri;

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

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

            return(request);
        }