当前位置: 首页>>代码示例>>Java>>正文


Java LeshanClient类代码示例

本文整理汇总了Java中org.eclipse.leshan.client.californium.LeshanClient的典型用法代码示例。如果您正苦于以下问题:Java LeshanClient类的具体用法?Java LeshanClient怎么用?Java LeshanClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LeshanClient类属于org.eclipse.leshan.client.californium包,在下文中一共展示了LeshanClient类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: register_with_additional_attributes

import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
@Test
public void register_with_additional_attributes() throws InterruptedException {
    // Check registration
    helper.assertClientNotRegisterered();

    // HACK to be able to send a Registration request with additional attributes
    LeshanClient lclient = helper.client;
    lclient.getCoapServer().start();
    Endpoint secureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getSecuredAddress());
    Endpoint nonSecureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getUnsecuredAddress());
    CaliforniumLwM2mRequestSender sender = new CaliforniumLwM2mRequestSender(secureEndpoint, nonSecureEndpoint);

    // Create Request with additional attributes
    Map<String, String> additionalAttributes = new HashMap<>();
    additionalAttributes.put("key1", "value1");
    additionalAttributes.put("imei", "2136872368");
    Link[] objectLinks = Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes());
    RegisterRequest registerRequest = new RegisterRequest(helper.getCurrentEndpoint(), null, null, null, null,
            objectLinks, additionalAttributes);

    // Send request
    RegisterResponse resp = sender.send(helper.server.getUnsecuredAddress(), false, registerRequest, 5000l);
    helper.waitForRegistration(1);

    // Check we are registered with the expected attributes
    helper.assertClientRegisterered();
    assertNotNull(helper.last_registration);
    assertEquals(additionalAttributes, helper.last_registration.getAdditionalRegistrationAttributes());
    assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes()),
            helper.getCurrentRegistration().getObjectLinks());

    sender.send(helper.server.getUnsecuredAddress(), false, new DeregisterRequest(resp.getRegistrationID()), 5000l);
    lclient.getCoapServer().stop();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:35,代码来源:RegistrationTest.java

示例2: main

import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
public static void main(final String[] args) {
    	
    	if(ConfigLoader.LoadFile()){
    		
    	    SerialConnector sc = new SerialConnector();
    	    TemperatureSensor tempSensor = new TemperatureSensor(sc);
    	    HumiditySensor humiSensor = new HumiditySensor(sc);
    	    LightActuator lightActuator = new LightActuator(sc);

	        // Get endpoint name
	        String endpoint = DEFAULT_ENDPOINT;
	
	        // Get server URI
	        String serverURI="coap://localhost:5083";
	
//	        byte[] pskIdentity = null;
//	        byte[] pskKey = null;
	
	        // get local address
	        String localAddress = "localhost";
	        int localPort = 6000;
	
	        // get secure local address
	        String secureLocalAddress = "localhost";
	        int secureLocalPort = 6001;
	
	        sc.start();
	
	     // Initialize object list
	        ObjectsInitializer initializer = new ObjectsInitializer();

            initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
            initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
	        
	        initializer.setClassForObject(DEVICE, KETIVirtualDevice.class);
	        initializer.setInstancesForObject(3303, tempSensor);
	        initializer.setInstancesForObject(3304, humiSensor);
	        initializer.setInstancesForObject(3311, lightActuator);
	        List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, 3303, 3304, 3311);

	        // Create client
	        LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
	        builder.setLocalAddress(localAddress, localPort);
	        builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
	        builder.setObjects(enablers);
	        final LeshanClient client = builder.build();

	        // Start the client
	        client.start();

	        // De-register on shutdown and stop client.
	        Runtime.getRuntime().addShutdownHook(new Thread() {
	            @Override
	            public void run() {
	                client.destroy(true); // send de-registration request before destroy
	            }
	        });
    		
    	} else {
    		LOG.error("Can not found the port.conf file!");
    	}
    }
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:63,代码来源:DeviceClient.java

示例3: createAndStartClient

import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
public static void createAndStartClient(String endpoint, String localAddress, int localPort,
        String secureLocalAddress, int secureLocalPort, boolean needBootstrap, String serverURI, byte[] pskIdentity,
        byte[] pskKey) {

    // Initialize object list
    ObjectsInitializer initializer = new ObjectsInitializer();
    if (needBootstrap) {
        if (pskIdentity == null)
            initializer.setInstancesForObject(SECURITY, noSecBootstap(serverURI));
        else
            initializer.setInstancesForObject(SECURITY, pskBootstrap(serverURI, pskIdentity, pskKey));
    } else {
        if (pskIdentity == null) {
            initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
            initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
        } else {
            initializer.setInstancesForObject(SECURITY, psk(serverURI, 123, pskIdentity, pskKey));
            initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
        }
    }
    initializer.setClassForObject(DEVICE, MyDevice.class);
    initializer.setInstancesForObject(LOCATION, locationInstance);
    List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, CONNECTIVITY_MONITORING, LOCATION, CONNECTIVITY_STATISTICS);

    // Create client
    LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
    builder.setLocalAddress(localAddress, localPort);
    builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
    builder.setObjects(enablers);
    final LeshanClient client = builder.build();

    LOG.info("Press 'w','a','s','d' to change reported Location.");

    // Start the client
    client.start();

    // De-register on shutdown and stop client.
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            client.destroy(true); // send de-registration request before destroy
        }
    });

    // Change the location through the Console
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
        String nextMove = scanner.next();
        locationInstance.moveLocation(nextMove);
    }
    scanner.close();
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:53,代码来源:LeshanClientDemo.java

示例4: getConnector

import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
private Connector getConnector(LeshanClient client) {
    CoapEndpoint endpoint = (CoapEndpoint) helper.client.getCoapServer()
            .getEndpoint(helper.client.getUnsecuredAddress());
    return endpoint.getConnector();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:6,代码来源:ObserveTest.java


注:本文中的org.eclipse.leshan.client.californium.LeshanClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。