org.eclipse.californium.core.coap.Request.getDestinationPort()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.eclipse.californium.core.coap.Request.getDestinationPort方法的一些代码示例,展示了Request.getDestinationPort的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getDestinationPort方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getDestinationPort

Request.getDestinationPort介绍

暂无

代码示例

代码示例来源:origin: eclipse/californium

/**
 * Validate before sending that there is a destination set.
 */
private void validateBeforeSending() {
  if (getDestination() == null)
    throw new NullPointerException("Destination is null");
  if (getDestinationPort() == 0)
    throw new NullPointerException("Destination port is 0");
}

代码示例来源:origin: eclipse/californium

@Override
public void sendRequest(Request request) {
  LOGGER.log(Level.INFO, "{0}:{1} <== req {2}", new Object[]{request.getDestination(), request.getDestinationPort(), request});
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Validate before sending that there is a destination set.
 */
private void validateBeforeSending() {
  if (getDestination() == null)
    throw new NullPointerException("Destination is null");
  if (getDestinationPort() == 0)
    throw new NullPointerException("Destination port is 0");
}

代码示例来源:origin: org.eclipse.californium/californium-core

@Override
public void sendRequest(Request request) {
  LOGGER.info(String.format("%s:%d <== req %s", request.getDestination(), request.getDestinationPort(), request));
}

代码示例来源:origin: eclipse/californium

@Test
public void testSetURISetsDestination() {
  InetSocketAddress dest = InetSocketAddress.createUnresolved("192.168.0.1", 12000);
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000");
  assertThat(req.getDestination().getHostAddress(), is(dest.getHostString()));
  assertThat(req.getDestinationPort(), is(dest.getPort()));
}

代码示例来源:origin: eclipse/californium

@Test
public void testSetURISetsDestinationPortBasedOnUriScheme() {
  Request req = Request.newGet().setURI("coap://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  req = Request.newGet().setURI("coaps://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  req = Request.newGet().setURI("coap+tcp://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  req = Request.newGet().setURI("coaps+tcp://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Serializes the specified request. Message identifier, message code,
 * token, options and payload are converted into a byte array and wrapped in
 * a {@link RawData} object. The request's destination address and port are
 * stored as address and port in the RawData object.
 * 
 * @param request
 *            the request
 * @return the request as raw data
 */
public RawData serialize(Request request) {
  byte[] bytes = request.getBytes();
  if (bytes == null)
    bytes = new DataSerializer().serializeRequest(request);
  request.setBytes(bytes);
  return new RawData(bytes, request.getDestination(), request.getDestinationPort());
}

代码示例来源:origin: eclipse/californium

@Test
public void testSetOptionsSetsUriHostOption() {
  Request req = Request.newGet();
  req.setDestination(InetAddress.getLoopbackAddress());
  req.setOptions(URI.create("coap://iot.eclipse.org"));
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  assertThat(req.getOptions().getUriHost(), is("iot.eclipse.org"));
}

代码示例来源:origin: eclipse/californium

/**
 * Returns the endpoint responsible for the given exchange.
 * @param exchange the exchange
 * @return the endpoint for the exchange
 */
public RemoteEndpoint getRemoteEndpoint(Exchange exchange){ //int remotePort, InetAddress remoteAddress){
  
  InetAddress remoteAddress = exchange.getRequest().getDestination();
  int remotePort = exchange.getRequest().getDestinationPort();
  
  // TODO: One IP-Address is considered to be a destination endpoint, for higher granularity (portnumber) changes are necessary
  if (!remoteEndpointsList.containsKey(remoteAddress)){
    RemoteEndpoint unusedRemoteEndpoint = new RemoteEndpoint(remotePort, remoteAddress, config);
    remoteEndpointsList.put(remoteAddress,unusedRemoteEndpoint);
    
    //System.out.println("Number of RemoteEndpoint objects stored:" + remoteEndpointsList.size());
  }
  
  return remoteEndpointsList.get(remoteAddress);
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Returns the endpoint responsible for the given exchange.
 * @param exchange the exchange
 * @return the endpoint for the exchange
 */
public RemoteEndpoint getRemoteEndpoint(Exchange exchange){ //int remotePort, InetAddress remoteAddress){
  
  InetAddress remoteAddress = exchange.getRequest().getDestination();
  int remotePort = exchange.getRequest().getDestinationPort();
  
  // TODO: One IP-Address is considered to be a destination endpoint, for higher granularity (portnumber) changes are necessary
  if (!remoteEndpointsList.containsKey(remoteAddress)){
    RemoteEndpoint unusedRemoteEndpoint = new RemoteEndpoint(remotePort, remoteAddress, config);
    remoteEndpointsList.put(remoteAddress,unusedRemoteEndpoint);
    
    //System.out.println("Number of RemoteEndpoint objects stored:" + remoteEndpointsList.size());
  }
  
  return remoteEndpointsList.get(remoteAddress);
}

代码示例来源:origin: eclipse/californium

@Override
  public void run() {
    if (!endpoint.getNonConfirmableQueue().isEmpty()) {
      endpoint.setProcessingNON(true);
      Exchange exchange = endpoint.getNonConfirmableQueue().poll();
      if (getRemoteEndpoint(exchange).getNonConfirmableCounter() <= MAX_SUCCESSIVE_NONS) {
        getRemoteEndpoint(exchange).increaseNonConfirmableCounter();
        if (exchange.getCurrentRequest().getDestinationPort() != 0) {
          // it's a response
          sendBucketRequest(exchange, exchange.getCurrentRequest());
        } else if (exchange.getCurrentResponse() != null) {
          // it's a request
          sendBucketResponse(exchange, exchange.getCurrentResponse());
        }
      }
      // schedule next transmission of a NON based on the RTO value (rate = 1/RTO)
      executor.schedule(
          new BucketThread(getRemoteEndpoint(exchange)),
          getRemoteEndpoint(exchange).getRTO(),
          TimeUnit.MILLISECONDS);
    } else {
      endpoint.setProcessingNON(false);
    }
  }
}

代码示例来源:origin: org.eclipse.californium/californium-core

@Override
  public void run() {
    if (!endpoint.getNonConfirmableQueue().isEmpty()) {
      endpoint.setProcessingNON(true);
      Exchange exchange = endpoint.getNonConfirmableQueue().poll();
      if (getRemoteEndpoint(exchange).getNonConfirmableCounter() <= MAX_SUCCESSIVE_NONS) {
        getRemoteEndpoint(exchange).increaseNonConfirmableCounter();
        if (exchange.getCurrentRequest().getDestinationPort() != 0) {
          // it's a response
          sendBucketRequest(exchange, exchange.getCurrentRequest());
        } else if (exchange.getCurrentResponse() != null) {
          // it's a request
          sendBucketResponse(exchange, exchange.getCurrentResponse());
        }
      }
      // schedule next transmission of a NON based on the RTO value (rate = 1/RTO)
      executor.schedule(
          new bucketThread(getRemoteEndpoint(exchange)),
          getRemoteEndpoint(exchange).getRTO(),
          TimeUnit.MILLISECONDS);
    } else {
      endpoint.setProcessingNON(false);
    }
  }        
}

代码示例来源:origin: eclipse/californium

/**
 * Verifies that the URI examples from <a href="https://tools.ietf.org/html/rfc7252#section-6.3">
 * RFC 7252, Section 6.3</a> result in the same option values.
 * @throws URISyntaxException 
 */
@Test
public void testSetOptionsCompliesWithRfcExample() throws URISyntaxException {
  String[] exampleUris = new String[]{
      "coap://example.com:5683/~sensors/temp.xml",
      "coap://EXAMPLE.com/%7Esensors/temp.xml",
      "coap://EXAMPLE.com:/%7esensors/temp.xml"
  };
  for (String uriString : exampleUris) {
    URI uri = new URI(uriString);
    Request req = Request.newGet();
    // explicitly set destination address so that we do not rely on working DNS
    req.setDestination(InetAddress.getLoopbackAddress());
    req.setOptions(uri);
    assertThat(req.getOptions().getUriHost(), is("example.com"));
    assertThat(req.getDestinationPort(), is(5683));
    assertThat(req.getOptions().getUriPort(), is(nullValue()));
    assertThat(req.getOptions().getUriPathString(), is("~sensors/temp.xml"));
  }
}

代码示例来源:origin: eclipse/californium

@Test
public void testSetURISetsUriHostOptionToHostName() {
  assumeTrue(dnsIsWorking());
  Request req = Request.newGet().setURI("coaps://localhost");
  assertNotNull(req.getDestination());
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  assertThat(req.getOptions().getUriHost(), is("localhost"));
}

代码示例来源:origin: eclipse/californium

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  // dispatch final response to the same message observers
  for (MessageObserver mo : request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  endpoint.sendRequest(cancel);
}

代码示例来源:origin: eclipse/californium

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  
  // dispatch final response to the same message observers
  for (MessageObserver mo: request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  
  endpoint.sendRequest(cancel);
}

代码示例来源:origin: org.eclipse.californium/californium-core

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: eclipse/californium

private static Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

代码示例来源:origin: eclipse/californium

private Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

相关文章