Java Code Examples for org.eclipse.californium.core.CoapServer#start()

The following examples show how to use org.eclipse.californium.core.CoapServer#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoapReceiverServer.java    From datacollector with Apache License 2.0 6 votes vote down vote up
public List<Stage.ConfigIssue> init(Stage.Context context) {
  List<Stage.ConfigIssue> issues = new ArrayList<>();
  NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
  networkConfig.set(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.NO_DEDUPLICATOR);
  networkConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  networkConfig.set(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  if (coAPServerConfigs.networkConfigs != null) {
    for (String key: coAPServerConfigs.networkConfigs.keySet()) {
      networkConfig.set(key, coAPServerConfigs.networkConfigs.get(key));
    }
  }
  coapServer = new CoapServer(networkConfig, coAPServerConfigs.port);
  coapReceiverResource = new CoapReceiverResource(context, receiver, errorQueue);
  coapServer.add(coapReceiverResource);
  coapServer.start();
  return issues;
}
 
Example 2
Source File: TestCoapClientTarget.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  int port =  TestHttpClientTarget.getFreePort();
  coapServer = new CoapServer(NetworkConfig.createStandardWithoutFile(), port);
  coapServer.add(new CoapResource("test") {
    @Override
    public void handlePOST(CoapExchange exchange) {
      serverRequested = true;
      if (returnErrorResponse) {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        return;
      }
      requestPayload = new String(exchange.getRequestPayload());
      exchange.respond(CoAP.ResponseCode.VALID);
    }
  });
  resourceURl = "coap://localhost:" + port + "/test";
  coapServer.start();
}
 
Example 3
Source File: HelloWorld2.java    From hands-on-coap with Eclipse Public License 1.0 6 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        // "hello"
        server.add(new HelloResource());

        // "subpath/Another"
        CoapResource path = new CoapResource("subpath");
        path.add(new AnotherResource());
        server.add(path);

        // "removeme!, "time", "writeme!"
        server.add(new RemovableResource(), new TimeResource(), new WritableResource());

        server.start();
    }
 
Example 4
Source File: IOTCoapServer.java    From IOT-Technical-Guide with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws UnknownHostException {

        CoapServer server = new CoapServer();


        server.add(new HelloResource());

        CoapResource path = new CoapResource("subpath");
        path.add(new AnotherResource());
        server.add(path);

        server.add(new RemovableResource(), new TimeResource(), new WritableResource());


        server.start();
    }
 
Example 5
Source File: HelloWorld2.java    From hands-on-coap with Eclipse Public License 1.0 3 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        // "hello"
        server.add(new HelloResource());

        // TODO "subpath/Another"

        // TODO "removeme!, "time", "writeme!"

        server.start();
    }
 
Example 6
Source File: HelloWorld1.java    From hands-on-coap with Eclipse Public License 1.0 3 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        server.add(new HelloResource());

        server.start();
    }