/// <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); }
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); } }