Package ch.ethz.inf.vs.californium.coap

Examples of ch.ethz.inf.vs.californium.coap.Request


    return code == EMPTY_CODE;
  }
 
  public Request parseRequest() {
    assert(isRequest());
    Request request = new Request(Code.valueOf(code));
    parseMessage(request);
    return request;
  }
View Full Code Here


   * @param timeout the time to wait for a pong in ms
   * @return success of the ping
   */
  public boolean ping(long timeout) {
    try {
      Request request = new Request(null);
      request.setType(Type.CON);
      request.setToken(new byte[0]);
      request.setURI(uri);
      request.send().waitForResponse(5000);
      request.cancel();
      return request.isRejected();
    } catch (InterruptedException e) {
      // waiting was interrupted, which is fine
    }
    return false;
  }
View Full Code Here

  public Set<WebLink> discover() {
    return discover(null);
  }
 
  public Set<WebLink> discover(String query) {
    Request discover = Request.newGet();
    discover.setURI(uri);
    discover.getOptions().clearURIPaths().clearURIQuery().setURIPath("/.well-known/core");
    if (query!=null) {
      discover.getOptions().setURIQuery(query);
    }
    CoapResponse links = synchronous(discover);
   
    // check if Link Format
    if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT)
View Full Code Here

   *
   * @param handler the Response handler
   * @return the CoAP observe relation
   */
  public CoapObserveRelation observeAndWait(CoapHandler handler) {
    Request request = Request.newGet().setURI(uri).setObserve();
    return observeAndWait(request, handler);
  }
View Full Code Here

   * @param handler the Response handler
   * @param accept the Accept option
   * @return the CoAP observe relation
   */
  public CoapObserveRelation observeAndWait(CoapHandler handler, int accept) {
    Request request = Request.newGet().setURI(uri).setObserve();
    request.getOptions().setAccept(accept);
    return observeAndWait(request, handler);
  }
View Full Code Here

   *
   * @param handler the Response handler
   * @return the CoAP observe relation
   */
  public CoapObserveRelation observe(CoapHandler handler) {
    Request request = Request.newGet().setURI(uri).setObserve();
    return observe(request, handler);
  }
View Full Code Here

   * @param handler the Response handler
   * @param accept the Accept option
   * @return the CoAP observe relation
   */
  public CoapObserveRelation observe(CoapHandler handler, int accept) {
    Request request = Request.newGet().setURI(uri).setObserve();
    return observe(accept(request, accept), handler);
  }
View Full Code Here

  /**
   * Proactive Observe cancellation:
   * Cancel the observe relation by sending a GET with Observe=1.
   */
  public void proactiveCancel() {
    Request cancel = Request.newGet();
    // copy options, but set Observe to cancel
    cancel.setOptions(request.getOptions());
    cancel.setObserveCancel();
    // use same Token
    cancel.setToken(request.getToken());
    cancel.setDestination(request.getDestination());
    cancel.setDestinationPort(request.getDestinationPort());
    // dispatch final response to the same message observers
    for (MessageObserver mo: request.getMessageObservers())
      cancel.addMessageObserver(mo);
    cancel.send();
    // cancel old ongoing request
    request.cancel();
    this.canceled = true;
  }
View Full Code Here

  /* (non-Javadoc)
   * @see ch.inf.vs.californium.MessageDeliverer#deliverRequest(ch.inf.vs.californium.network.Exchange)
   */
  @Override
  public void deliverRequest(final Exchange exchange) {
    Request request = exchange.getRequest();
    List<String> path = request.getOptions().getURIPaths();
    final Resource resource = findResource(path);
    if (resource != null) {
      checkForObserveOption(exchange, resource);
     
      // Get the executor and let it process the request
View Full Code Here

   *            the target resource
   * @param path
   *            the path to the resource
   */
  private void checkForObserveOption(Exchange exchange, Resource resource) {
    Request request = exchange.getRequest();
    if (request.getCode() != Code.GET) return;

    InetSocketAddress source = new InetSocketAddress(request.getSource(), request.getSourcePort());

    if (request.getOptions().hasObserve() && resource.isObservable()) {
     
      if (request.getOptions().getObserve()==0) {
        // Requests wants to observe and resource allows it :-)
        LOGGER.info("Initiate an observe relation between " + request.getSource() + ":" + request.getSourcePort() + " and resource " + resource.getURI());
        ObservingEndpoint remote = observeManager.findObservingEndpoint(source);
        ObserveRelation relation = new ObserveRelation(remote, resource, exchange);
        remote.addObserveRelation(relation);
        exchange.setRelation(relation);
        // all that's left is to add the relation to the resource which
        // the resource must do itself if the response is successful
      } else if (request.getOptions().getObserve()==1) {
        ObserveRelation relation = observeManager.getRelation(source, request.getToken());
        if (relation!=null) relation.cancel();
      }
    }
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.coap.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.