@Override protected final int getActualPort() { int port = Constants.PORT_UNCONFIGURED; final Endpoint endpoint = secureEndpoint; if (endpoint != null) { port = endpoint.getAddress().getPort(); } return port; }
@Override protected final int getActualInsecurePort() { int port = Constants.PORT_UNCONFIGURED; final Endpoint endpoint = insecureEndpoint; if (endpoint != null) { port = endpoint.getAddress().getPort(); } return port; }
/** * Returns the endpoint with a specific socket address. * @param address the socket address * @return the endpoint */ @Override public Endpoint getEndpoint(InetSocketAddress address) { Endpoint endpoint = null; for (Endpoint ep : endpoints) { if (ep.getAddress().equals(address)) { endpoint = ep; break; } } return endpoint; }
/** * Returns the endpoint with a specific port. * @param port the port * @return the endpoint */ @Override public Endpoint getEndpoint(int port) { Endpoint endpoint = null; for (Endpoint ep : endpoints) { if (ep.getAddress().getPort() == port) { endpoint = ep; } } return endpoint; }
/** * Returns the endpoint with a specific socket address. * @param address the socket address * @return the endpoint */ @Override public Endpoint getEndpoint(InetSocketAddress address) { Endpoint endpoint = null; for (Endpoint ep : endpoints) { if (ep.getAddress().equals(address)) { endpoint = ep; break; } } return endpoint; }
/** * Returns the endpoint with a specific port. * @param port the port * @return the endpoint */ @Override public Endpoint getEndpoint(int port) { Endpoint endpoint = null; for (Endpoint ep : endpoints) { if (ep.getAddress().getPort() == port) { endpoint = ep; } } return endpoint; }
public InetSocketAddress getAddress() { return endpointsManager.getEndpoint(null).getAddress(); }
private synchronized void createDefaultEndpoint() { if (default_endpoint != null) return; default_endpoint = new CoapEndpoint(); try { default_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit default endpoint {0}", default_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create default endpoint", e); } }
private synchronized void createDefaultEndpoint() { if (default_endpoint != null) return; default_endpoint = new CoapEndpoint(); try { default_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit default endpoint " + default_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create default endpoint", e); } }
/** * Creates a URI string for a resource hosted on an endpoint. * * @param endpoint The endpoint the resource is hosted on. * @param path The path of the resource on the endpoint. * @return The URI string. */ public static String getUri(final Endpoint endpoint, final String path) { return getUri(endpoint.getAddress(), path); }
@Override public T buildResponse(Response coapResponse) { // TODO we need to fix that by removing the Client dependency from LwM2MResponseBuilder or by creating a // LwM2mBootstrapResponseBuilder Registration registration = new Registration.Builder("fakeregistrationid", endpointName, destination, destination.isSecure() ? secureEndpoint.getAddress() : nonSecureEndpoint.getAddress()).build(); // Build LwM2m response LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse, registration, model, null, decoder); request.accept(lwm2mResponseBuilder); return lwm2mResponseBuilder.getResponse(); } };
@Override public T buildResponse(Response coapResponse) { // TODO we need to fix that by removing the Client dependency from LwM2MResponseBuilder or by creating a // LwM2mBootstrapResponseBuilder Registration registration = new Registration.Builder("fakeregistrationid", endpointName, destination, destination.isSecure() ? secureEndpoint.getAddress() : nonSecureEndpoint.getAddress()).build(); // Build LwM2m response LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse, registration, model, null, decoder); request.accept(lwm2mResponseBuilder); return lwm2mResponseBuilder.getResponse(); } };
@Before public void setupEndpoints() throws Exception { client = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), config); client.addInterceptor(clientInterceptor); client.start(); System.out.println("Client binds to port " + client.getAddress().getPort()); server = createLockstepEndpoint(client.getAddress()); }
private synchronized void createTcpEndpoint() { if (default_tcp_endpoint != null) return; NetworkConfig config = NetworkConfig.getStandard(); TcpClientConnector connector = new TcpClientConnector(config.getInt(NetworkConfig.Keys.TCP_WORKER_THREADS), config.getInt(NetworkConfig.Keys.TCP_CONNECT_TIMEOUT), config.getInt(NetworkConfig.Keys.TCP_CONNECTION_IDLE_TIMEOUT)); default_tcp_endpoint = new CoapEndpoint(connector, config); try { default_tcp_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit tcp endpoint {0}", default_tcp_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create tcp endpoint", e); } }
private synchronized void createSecureTcpEndpoint() { if (default_secure_tpc_endpoint != null) return; NetworkConfig config = NetworkConfig.getStandard(); TlsClientConnector connector = new TlsClientConnector(config.getInt(NetworkConfig.Keys.TCP_WORKER_THREADS), config.getInt(NetworkConfig.Keys.TCP_CONNECT_TIMEOUT), config.getInt(NetworkConfig.Keys.TCP_CONNECTION_IDLE_TIMEOUT)); default_secure_tpc_endpoint = new CoapEndpoint(connector, config); try { default_secure_tpc_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit secure tcp endpoint {0}", default_secure_tpc_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create secure tcp endpoint", e); } }
@Before public void setupEndpoints() throws Exception { //exchangeStore = new InMemoryMessageExchangeStore(CONFIG, new InMemoryRandomTokenProvider(CONFIG)); // bind to loopback address using an ephemeral port // CoapEndpoint udpEndpoint = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), CONFIG, exchangeStore); client = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), CONFIG); client.addInterceptor(clientInterceptor); client.addInterceptor(new MessageTracer()); client.start(); System.out.println("Client binds to port " + client.getAddress().getPort()); server = createLockstepEndpoint(client.getAddress()); }
@BeforeClass public static void startupServer() { network.getStandardTestConfig().setLong(NetworkConfig.Keys.MAX_TRANSMIT_WAIT, 100); createServer(); System.out.println(System.lineSeparator() + "Start " + ClientSynchronousTest.class.getSimpleName() + " on " + serverEndpoint.getAddress()); }
private static void createServer() { serverEndpoint = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); resource = new StorageResource(TARGET, CONTENT_1); server = new CoapServer(); server.add(resource); server.addEndpoint(serverEndpoint); server.start(); serverPort = serverEndpoint.getAddress().getPort(); }
@Before public void setupServer() throws Exception { System.out.println(System.lineSeparator() + "Start " + getClass().getSimpleName()); NetworkConfig config = network.createTestConfig() .setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 128) .setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 128) .setInt(NetworkConfig.Keys.ACK_TIMEOUT, 200) // client retransmits after 200 ms .setInt(NetworkConfig.Keys.ACK_RANDOM_FACTOR, 1); client = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), config); client.addInterceptor(new MessageTracer()); client.start(); clientPort = client.getAddress().getPort(); server = createLockstepEndpoint(client.getAddress()); System.out.println("Client binds to port " + clientPort); }
@Before public void setupEndpoints() throws Exception { testResource = new TestResource("test"); exchangeStore = new InMemoryMessageExchangeStore(CONFIG); // bind to loopback address using an ephemeral port CoapEndpoint udpEndpoint = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), CONFIG, exchangeStore); server = new CoapServer(); server.addEndpoint(udpEndpoint); server.add(testResource); server.getEndpoints().get(0).addInterceptor(serverInterceptor); server.start(); InetSocketAddress serverAddress = server.getEndpoints().get(0).getAddress(); System.out.println("Server binds to port " + serverAddress.getPort()); client = createLockstepEndpoint(serverAddress); }