Class CoapClient
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
optionsCoapClientOptionsThe 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
Exceptions
- PamojaException
The socket could not be bound.
DisconnectAsync()
Releases the socket the endpoint holds.
public Task DisconnectAsync()
Returns
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
ReceiveAsync()
Waits for the next message on an observed path.
public Task<TransportMessage?> ReceiveAsync()
Returns
- Task<TransportMessage>
The message, or
nullonce 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
topicstringThe resource path.
payloadReadOnlyMemory<byte>The bytes to send.
Returns
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
topicstringThe resource path.
Returns
Exceptions
- PamojaException
The observation was refused.