Search in sources :

Example 1 with UdpDataSerializer

use of org.eclipse.californium.core.network.serialization.UdpDataSerializer in project leshan by eclipse.

the class LockStepLwM2mClient method sendLwM2mRequest.

public void sendLwM2mRequest(UplinkRequest<? extends LwM2mResponse> lwm2mReq) {
    // create CoAP request
    CoapRequestBuilder coapRequestBuilder = new CoapRequestBuilder(destination);
    lwm2mReq.accept(coapRequestBuilder);
    Request coapReq = coapRequestBuilder.getRequest();
    byte[] token = new byte[8];
    r.nextBytes(token);
    coapReq.setToken(token);
    // serialize request
    UdpDataSerializer serializer = new UdpDataSerializer();
    RawData raw = serializer.serializeRequest(coapReq);
    // send it
    super.send(raw);
}
Also used : RawData(org.eclipse.californium.elements.RawData) CoapRequestBuilder(org.eclipse.leshan.client.californium.impl.CoapRequestBuilder) Request(org.eclipse.californium.core.coap.Request) UplinkRequest(org.eclipse.leshan.core.request.UplinkRequest) UdpDataSerializer(org.eclipse.californium.core.network.serialization.UdpDataSerializer)

Example 2 with UdpDataSerializer

use of org.eclipse.californium.core.network.serialization.UdpDataSerializer in project leshan by eclipse.

the class ObserveTest method sendNotification.

private void sendNotification(Connector connector, byte[] payload, Response firstCoapResponse, int contentFormat) {
    // create observe response
    Response response = new Response(org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT);
    response.setType(Type.NON);
    response.setPayload(payload);
    response.setMID(firstCoapResponse.getMID() + 1);
    response.setToken(firstCoapResponse.getToken());
    OptionSet options = new OptionSet().setContentFormat(contentFormat).setObserve(firstCoapResponse.getOptions().getObserve() + 1);
    response.setOptions(options);
    EndpointContext context = new AddressEndpointContext(helper.server.getUnsecuredAddress().getAddress(), helper.server.getUnsecuredAddress().getPort());
    response.setDestinationContext(context);
    // serialize response
    UdpDataSerializer serializer = new UdpDataSerializer();
    RawData data = serializer.serializeResponse(response);
    // send it
    connector.send(data);
}
Also used : Response(org.eclipse.californium.core.coap.Response) LwM2mResponse(org.eclipse.leshan.core.response.LwM2mResponse) ObserveResponse(org.eclipse.leshan.core.response.ObserveResponse) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) RawData(org.eclipse.californium.elements.RawData) AddressEndpointContext(org.eclipse.californium.elements.AddressEndpointContext) EndpointContext(org.eclipse.californium.elements.EndpointContext) AddressEndpointContext(org.eclipse.californium.elements.AddressEndpointContext) OptionSet(org.eclipse.californium.core.coap.OptionSet) UdpDataSerializer(org.eclipse.californium.core.network.serialization.UdpDataSerializer)

Aggregations

UdpDataSerializer (org.eclipse.californium.core.network.serialization.UdpDataSerializer)2 RawData (org.eclipse.californium.elements.RawData)2 OptionSet (org.eclipse.californium.core.coap.OptionSet)1 Request (org.eclipse.californium.core.coap.Request)1 Response (org.eclipse.californium.core.coap.Response)1 AddressEndpointContext (org.eclipse.californium.elements.AddressEndpointContext)1 EndpointContext (org.eclipse.californium.elements.EndpointContext)1 CoapRequestBuilder (org.eclipse.leshan.client.californium.impl.CoapRequestBuilder)1 UplinkRequest (org.eclipse.leshan.core.request.UplinkRequest)1 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)1 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)1 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)1