public static void selfTest() { try { Request request = Request.newGet(); request.setURI("localhost:5683/benchmark"); request.send(); Response response = request.waitForResponse(1000); System.out.println("received "+response); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void sendNotification(String url, String payload) { Request request = Request.newPost(); request.setURI(url); request.setPayload(payload); request.send(); LOG.debug("CoAP: Send notification uri: {}, payload: {}:", url, payload); }
request.send(); if (sync) { request.waitForResponse(5000);
private static boolean ping(String address) { try { Request request = new Request(null); request.setType(Type.CON); request.setToken(new byte[0]); request.setURI(address); System.out.println("++++++ Sending Ping ++++++"); request.send().waitForResponse(5000); return request.isRejected(); } catch (Exception e) { e.printStackTrace(); return false; } }
boolean success = true; request.send();
outgoingRequest.send();
outgoingRequest.send();
postSecurity.setPayload(encoded.array()); postSecurity.send(e).addMessageObserver(new MessageObserver() {
postServer.setDestinationPort(targetPort); postServer.setPayload(encoded.array()); postServer.send(e).addMessageObserver(new MessageObserver() { @Override public void onTimeout() {
private void sendRequestAndExpect(String expected) throws Exception { System.out.println(); Thread.sleep(100); Request request = Request.newGet(); request.setURI("localhost:"+serverPort+"/res"); String response = request.send().waitForResponse(1000).getPayloadString(); Assert.assertEquals(expected, response); }
coapRequest.send(); Response coapResponse = coapRequest.waitForResponse(); if (null == coapResponse) {
/** * Verifies that the server cleans up all exchanges after serving a NON GET. * * @throws Exception if the test fails. */ @Test public void testSimpleNONGet() throws Exception { String uri = uriOf(URI); LOGGER.log(Level.FINE, "Test simple NON GET to {0}", uri); String currentResponseText = "simple NON GET"; resource.setResponse(currentResponseText, Mode.PIGGY_BACKED_RESPONSE); Request request = Request.newGet(); request.setURI(uri); request.setType(Type.NON); Response response = request.send(clientEndpoint).waitForResponse(ACK_TIMEOUT); assertThat("Client did not receive response to NON request in time", response, is(notNullValue())); LOGGER.log(Level.FINE, "Client received response [{0}] with msg type [{1}]", new Object[]{response.getPayloadString(), response.getType()}); assertThat(response.getPayloadString(), is(currentResponseText)); assertThat(response.getType(), is(Type.NON)); }
@Test public void testNonconfirmable() throws Exception { createSimpleServer(); // send request Request request = new Request(CoAP.Code.POST); request.setConfirmable(false); request.setDestination(InetAddress.getLoopbackAddress()); request.setDestinationPort(serverPort); request.setPayload("client says hi"); request.send(); System.out.println("client sent request"); // receive response and check Response response = request.waitForResponse(1000); assertNotNull("Client received no response", response); System.out.println("client received response"); assertEquals(response.getPayloadString(), SERVER_RESPONSE); }
String resp1 = Request.newGet().setURI(base+NAME_1).send().waitForResponse(1000).getPayloadString(); Assert.assertEquals(PAYLOAD, resp1); String resp2 = Request.newGet().setURI(base+NAME_1+"/"+CHILD).send().waitForResponse(1000).getPayloadString(); Assert.assertEquals(CHILD_PAYLOAD, resp2); String resp3 = Request.newGet().setURI(base+NAME_2).send().waitForResponse(1000).getPayloadString(); Assert.assertEquals(PAYLOAD, resp3); String resp4 = Request.newGet().setURI(base+NAME_2+"/"+CHILD).send().waitForResponse(1000).getPayloadString(); Assert.assertEquals(CHILD_PAYLOAD, resp4); ResponseCode code1 = Request.newGet().setURI(base+NAME_1).send().waitForResponse(1000).getCode(); Assert.assertEquals(ResponseCode.NOT_FOUND, code1); ResponseCode code2 = Request.newGet().setURI(base+NAME_1+"/"+CHILD).send().waitForResponse(1000).getCode(); Assert.assertEquals(ResponseCode.NOT_FOUND, code2);
deleteAll.setDestinationPort(exchange.getSourcePort()); deleteAll.send(e).addMessageObserver(new MessageObserver() {
@Test public void testConfirmable() throws Exception { // send request Request req2acc = new Request(Code.POST); req2acc.setConfirmable(true); req2acc.setURI(getUri(ACC_RESOURCE)); req2acc.setPayload("client says hi"); req2acc.send(); // receive response and check Response response = req2acc.waitForResponse(1000); assertPayloadIsOfCorrectType(response, SERVER_RESPONSE, Type.CON); Request req2noacc = new Request(Code.POST); req2noacc.setConfirmable(true); req2noacc.setURI(getUri(NO_ACC_RESOURCE)); req2noacc.setPayload("client says hi"); req2noacc.send(); // receive response and check response = req2noacc.waitForResponse(1000); assertPayloadIsOfCorrectType(response, SERVER_RESPONSE, Type.ACK); }
@Test public void testNonConfirmable() throws Exception { // send request Request req2acc = new Request(Code.POST); req2acc.setConfirmable(false); req2acc.setURI(getUri(ACC_RESOURCE)); req2acc.setPayload("client says hi"); req2acc.send(); // receive response and check Response response = req2acc.waitForResponse(1000); assertPayloadIsOfCorrectType(response, SERVER_RESPONSE, Type.NON); Request req2noacc = new Request(Code.POST); req2noacc.setConfirmable(false); req2noacc.setURI(getUri(NO_ACC_RESOURCE)); req2noacc.setPayload("client says hi"); req2noacc.send(); // receive response and check response = req2noacc.waitForResponse(1000); assertPayloadIsOfCorrectType(response, SERVER_RESPONSE, Type.NON); }
request.getOptions().setBlock2(szx, false, num); Response response = request.send().waitForResponse(1000); Assert.assertNotNull("Client received no response", response); Assert.assertEquals(expectations[i], response.getPayloadString());