Table of Contents

Class CoapClient

Namespace
Pamoja.Coap
Assembly
Pamoja.Coap.dll

A CoAP endpoint.

public sealed class CoapClient : IDisposable
Inheritance
CoapClient
Implements
Inherited Members

Remarks

CoAP is the transport for links where MQTT is more than the budget allows: it runs over UDP, its headers are a handful of bytes, and a node can fire a reading and forget it rather than holding a session open.

Constructors

CoapClient(CoapClientOptions)

Creates a disconnected endpoint from the given settings.

public CoapClient(CoapClientOptions options)

Parameters

options CoapClientOptions

The endpoint settings.

Exceptions

PamojaException

The native endpoint could not be created.

Methods

ConnectAsync()

Binds the local socket so the endpoint can carry traffic.

public Task ConnectAsync()

Returns

Task

Exceptions

PamojaException

The socket could not be bound.

DisconnectAsync()

Releases the socket the endpoint holds.

public Task DisconnectAsync()

Returns

Task

Exceptions

PamojaException

The native call failed.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

IsConnectedAsync()

Reports whether the local socket is bound.

public Task<bool> IsConnectedAsync()

Returns

Task<bool>

true when bound.

ReceiveAsync()

Waits for the next message on an observed path.

public Task<TransportMessage?> ReceiveAsync()

Returns

Task<TransportMessage>

The message, or null once the endpoint is closed.

Exceptions

PamojaException

The native call failed.

SendAsync(string, ReadOnlyMemory<byte>)

Sends a payload to a resource path.

public Task SendAsync(string topic, ReadOnlyMemory<byte> payload)

Parameters

topic string

The resource path.

payload ReadOnlyMemory<byte>

The bytes to send.

Returns

Task

Exceptions

PamojaException

The request could not be sent.

SubscribeAsync(string)

Observes a resource path, so messages published to it arrive.

public Task SubscribeAsync(string topic)

Parameters

topic string

The resource path.

Returns

Task

Exceptions

PamojaException

The observation was refused.