CoapClient

A CoAP client

Constructors

this
this(Address address)

Creates a new CoAP client to the provided endpoint address

this
this(string host, ushort port)

Constructs a new CoAP client to the provided endpoint address and port.

Members

Functions

close
void close()

Stops this client

doRequest
CoapRequestFuture doRequest(CoapRequestBuilder requestBuilder)

Given the builder this will extract the details required to encode the CoAP packet into its byte form, register a coap request internally and return a future for this request.

newRequestBuilder
CoapRequestBuilder newRequestBuilder()

Creates a new CoAP request builder

onNoNewMessages
void onNoNewMessages()

The intention of this method is that some kind-of CoapMessagingLayer can call this when it has no new messages to process.

setExchangeLifetime
void setExchangeLifetime(Duration lifetime)

Sets the exchange lifetime. In other words the duration of time that must pass before a message ID is considered free-for-use again

yankRequest
CoapRequest yankRequest(CoapPacket packet)

Given a packet this will try and find an active request with a matching token and return it.

Variables

address
Address address;

CoAP server endpoint

running
bool running;

Running status

Examples

Tests the client

In the future dogfooding should be used and we should test against our own server too.

// Address[] resolved = getAddress("coap.me");
// resolved[0].po
Address addr = new InternetAddress("coap.me", 5683);
// CoapClient client = new CoapClient(addr);

// client.resource("/hello");

// client.connect();

// Test sending something
CoapPacket packet = new CoapPacket();
packet.setCode(Code.POST);
packet.setToken([69]);
packet.setPayload(cast(ubyte[])"My custom payload");
packet.setType(MessageType.CONFIRMABLE);
packet.setMessageId(257);

// client.socket.send(packet.getBytes());

Meta