public void TestConfirmable() { // send request Request req2acc = new Request(Method.POST, true); req2acc.SetUri("localhost:" + _serverPort + "/" + ACC_RESOURCE); req2acc.SetPayload("client says hi"); req2acc.Send(); // receive response and check Response response = req2acc.WaitForResponse(100); Assert.IsNotNull(response); Assert.AreEqual(response.PayloadString, SERVER_RESPONSE); Assert.AreEqual(response.Type, MessageType.CON); Request req2noacc = new Request(Method.POST, true); req2noacc.SetUri("coap://localhost:" + _serverPort + "/" + NO_ACC_RESOURCE); req2noacc.SetPayload("client says hi"); req2noacc.Send(); // receive response and check response = req2noacc.WaitForResponse(100); Assert.IsNotNull(response); Assert.AreEqual(response.PayloadString, SERVER_RESPONSE); Assert.AreEqual(response.Type, MessageType.ACK); }
private void ExecutePOSTRequest() { String payload = "--no payload--"; try { Request request = new Request(Method.POST); request.SetUri("coap://localhost:" + _serverPort + "/" + request_short + respond_short); if (request_short) request.SetPayload(SHORT_POST_REQUEST); else request.SetPayload(LONG_POST_REQUEST); request.Send(_clientEndpoint); // receive response and check Response response = request.WaitForResponse(1000); Assert.IsNotNull(response); payload = response.PayloadString; if (respond_short) Assert.AreEqual(SHORT_POST_RESPONSE, payload); else Assert.AreEqual(LONG_POST_RESPONSE, payload); } finally { Thread.Sleep(100); // Quickly wait until last ACKs arrive } }
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); } }
public void TestConfirmable() { // send request Request req2acc = new Request(Method.POST, true); req2acc.SetUri("localhost:" + _serverPort + "/" + ACC_RESOURCE); req2acc.SetPayload("client says hi"); req2acc.Send(); // receive response and check Response response = req2acc.WaitForResponse(100); Assert.IsNotNull(response); Assert.AreEqual(response.PayloadString, SERVER_RESPONSE); Assert.AreEqual(response.Type, MessageType.CON); Request req2noacc = new Request(Method.POST, true); req2noacc.SetUri("coap://localhost:" + _serverPort + "/" + NO_ACC_RESOURCE); req2noacc.SetPayload("client says hi"); req2noacc.Send(); // receive response and check response = req2noacc.WaitForResponse(100); Assert.IsNotNull(response); Assert.AreEqual(response.PayloadString, SERVER_RESPONSE); Assert.AreEqual(response.Type, MessageType.ACK); }
private void ExecuteGETRequest() { String payload = "nothing"; try { Request request = Request.NewGet(); request.Destination = new IPEndPoint(IPAddress.Loopback, _serverPort); request.Send(_clientEndpoint); // receive response and check Response response = request.WaitForResponse(1000); Assert.IsNotNull(response); payload = response.PayloadString; if (respond_short) { Assert.AreEqual(SHORT_GET_RESPONSE, payload); } else { Assert.AreEqual(LONG_GET_RESPONSE, payload); } } finally { Thread.Sleep(100); // Quickly wait until last ACKs arrive } }
private void ExecutePOSTRequest() { String payload = "--no payload--"; try { Request request = new Request(Method.POST); request.SetUri("coap://localhost:" + _serverPort + "/" + request_short + respond_short); if (request_short) { request.SetPayload(SHORT_POST_REQUEST); } else { request.SetPayload(LONG_POST_REQUEST); } request.Send(_clientEndpoint); // receive response and check Response response = request.WaitForResponse(1000); Assert.IsNotNull(response); payload = response.PayloadString; if (respond_short) { Assert.AreEqual(SHORT_POST_RESPONSE, payload); } else { Assert.AreEqual(LONG_POST_RESPONSE, payload); } } finally { Thread.Sleep(100); // Quickly wait until last ACKs arrive } }