Search in sources :

Example 1 with MyIpResource

use of org.eclipse.californium.core.server.resources.MyIpResource in project californium by eclipse.

the class MulticastTestServer method main.

public static void main(String[] args) throws UnknownHostException {
    Configuration config = Configuration.createWithFile(CONFIG_FILE, CONFIG_HEADER, DEFAULTS);
    Configuration.setStandard(config);
    int unicastPort = config.get(CoapConfig.COAP_PORT);
    int multicastPort = unicastPort;
    switch(args.length) {
        default:
            System.out.println("usage: MulticastTestServer [unicast-port [multicast-port]]");
        case 2:
            multicastPort = Integer.parseInt(args[1]);
        case 1:
            unicastPort = Integer.parseInt(args[0]);
        case 0:
    }
    CoapServer server = new CoapServer(config);
    createEndpoints(server, unicastPort, multicastPort, config);
    server.add(new HelloWorldResource());
    server.add(new MyIpResource(MyIpResource.RESOURCE_NAME, true));
    server.start();
}
Also used : Configuration(org.eclipse.californium.elements.config.Configuration) CoapServer(org.eclipse.californium.core.CoapServer) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) MyIpResource(org.eclipse.californium.core.server.resources.MyIpResource)

Example 2 with MyIpResource

use of org.eclipse.californium.core.server.resources.MyIpResource in project californium by eclipse.

the class ServerService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("coap", "onStartCommand service");
    executor.execute(new Runnable() {

        @Override
        public void run() {
            Configuration config = Configuration.createStandardWithoutFile();
            CoapServer server = new CoapServer(config);
            NetworkInterface multicast = NetworkInterfacesUtil.getMulticastInterface();
            if (multicast == null) {
                setupUdp(server, config);
            } else {
                setupUdpIpv4(server, config);
                setupUdpIpv6(server, config);
            }
            setupDtls(server, config);
            server.add(new HelloWorldResource());
            server.add(new MyIpResource(MyIpResource.RESOURCE_NAME, true));
            startServer(server);
        }
    });
    return START_STICKY;
}
Also used : Configuration(org.eclipse.californium.elements.config.Configuration) CoapServer(org.eclipse.californium.core.CoapServer) NetworkInterface(java.net.NetworkInterface) MyIpResource(org.eclipse.californium.core.server.resources.MyIpResource)

Aggregations

CoapServer (org.eclipse.californium.core.CoapServer)2 MyIpResource (org.eclipse.californium.core.server.resources.MyIpResource)2 Configuration (org.eclipse.californium.elements.config.Configuration)2 NetworkInterface (java.net.NetworkInterface)1 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)1