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);
}
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);
}
Aggregations