-
Notifications
You must be signed in to change notification settings - Fork 20
CoapClient
The CoapClient class provides for a simple to use object which can be used by client applications. While one can do a great number of things using this class, there are some cases where one would need to create a request using the base request class in order to get some combinations of options set.
Uri: The URI to connect to
UriPath: Relative path to the Uri to be added when the message is processed. Added in version 1.6
UriQuery: Query to add to the Uri when the message is processed. Added in version 1.6
EndPoint: The endpoint to use. If no endpoint has been given, then the default UDP endpoint will be used.
Timeout: How long to wait before returning for synchronous API functions. The default value is infinity. If there is any possibility that a response might not be returned, it is highly recommended that this value be changed.
Blockwise: Allows for doing early blockwise size requests. If the value is 0 then no block option is sent in a request. Otherwise the given value will be used when computing the blockwise option to be sent.
Respond: List of functions to call when a response arrives.
Error: List of functions to call when an error occurs processing the request. Given the task based structure of the system users should not expect that all errors are going to generate these events.
OscoapContext: The OSCOAP context to use to encrypt the messages sent. Added in version 1.8
Delete - Perform a delete operation on the URI.
DeleteAsync - Perform a delete operation.
Discover - Perform a get using the well known URI for CoAP and the host fields of the set URI.
Get - Preform a get on the URI. It takes an optional parameter for the Accept option which controls the content format expected in the response.
GetAsync - Perform a get on the URI. It takes an optional parameter for the Accept option which controls the content format expected in the response.
Observe -
Post - Perform a post on the URI. It takes an optional parameter for the Accept option which controls the content format expected in the response.
PostAsync - Perform a post on the URI. It takes an optional parameter for the Accept option which controls the content format expected in the response.
Put - Perform a put on the URI. It has an optional parameter for the Accept option.
PutIfMatch -
PutIfNonMatch -
PutAsync - Perform a put on the URI.
Send - Send a user prepared request message.
SendAsync - Send a user prepared request message.
Validate - Determine if the etags from a previous response are still valid.
Ping - Performs a CoAP ping and gives up after the given number of milliseconds. This can be used as a keep alive message or to see if a server is up. This does not need to be preformed for reliable transports.
UseCONSs - Send confirmable messages to the server. This is the default.
UseNONs - Send non-confirmable messages to the server.
UseEarlyNegotiation - Include an option when sending a request that will set the system up for doing blocking by specifying a size that data should be blocked to. This is only needed if it is known that there are going to be limitations on the size of a UDP packet that are smaller than normal.
UseLateNegotiation - Don't include an option when sending a request that will set the system up for doing blocking. This is the default. If a blocking size other than what the server wants, it will be taken from the configuration that was provided when the object was constructed.
CoapClient client = new CoapClient(new Uri("coap://example.com"));
IEnumerable<WebLink> items = client.Discover();
foreach (var node in items) {
if (!node.Attributes.Contains("ct") && node.Attributes.GetContentTypes()[0] != 0) continue;
client.UriPath = node.Uri;
Response response = client.Get();
Console.WriteLine(" Payload = " + response.PayloadString);
}