![]() |
VOOZH | about |
dotnet add package CoAP.NET --version 1.0.4
NuGet\Install-Package CoAP.NET -Version 1.0.4
<PackageReference Include="CoAP.NET" Version="1.0.4" />
<PackageVersion Include="CoAP.NET" Version="1.0.4" />Directory.Packages.props
<PackageReference Include="CoAP.NET" />Project file
paket add CoAP.NET --version 1.0.4
#r "nuget: CoAP.NET, 1.0.4"
#:package CoAP.NET@1.0.4
#addin nuget:?package=CoAP.NET&version=1.0.4Install as a Cake Addin
#tool nuget:?package=CoAP.NET&version=1.0.4Install as a Cake Tool
The Constrained Application Protocol (CoAP) (https://datatracker.ietf.org/doc/draft-ietf-core-coap/) is a RESTful web transfer protocol for resource-constrained networks and nodes. CoAP.NET is an implementation in C# providing CoAP-based services to .NET applications. Reviews and suggestions would be appreciated.
Copyright (c) 2011-2013, Longxiang He <>, SmeshLink Technology Co.
Copyright (c) 2016-2020, Jim Schaad <>
Copyright (c) 2023-, Stephen Berard <>
The C# implementation is available in the NuGet Package Gallery under the name CoAP.NET. To install this library as a NuGet package, enter 'Install-Package CoAP.NET' in the NuGet Package Manager Console.
Coming soon
Access remote CoAP resources by issuing a and receive its (s).
// new a GET request
Request request = new Request(Method.GET);
request.URI = new Uri("coap://[::1]/hello-world");
request.Send();
// wait for one response
Response response = request.WaitForResponse();
There are 4 types of request: GET, POST, PUT, DELETE, defined as
Method.GET, Method.POST, Method.PUT, and Method.DELETE.
Responses can be received in two ways. By calling request.WaitForResponse()
a response will be received synchronously, which means it will
block until timeout or a response is arrived. If more responses
are expected, call WaitForResponse() again.
To receive responses asynchronously, register a event handler to
the event request.Respond before executing.
Parsing Link Format
Use LinkFormat.Parse(String) to parse a link-format
response. The returned enumeration of WebLink
contains all resources stated in the given link-format string.
Request request = new Request(Method.GET);
request.URI = new Uri("coap://[::1]/.well-known/core");
request.Send();
Response response = request.WaitForResponse();
IEnumerable<WebLink> links = LinkFormat.Parse(response.PayloadString);
See for more.
A new CoAP server can be easily built with help of the class
static void Main(String[] args)
{
CoapServer server = new CoapServer();
server.Add(new HelloWorldResource("hello"));
server.Start();
Console.ReadKey();
}
See for more.
CoAP resources are classes that can be accessed by a URI via CoAP.
In CoAP.NET, a resource is defined as a subclass of .
By overriding methods DoGet, DoPost, DoPut, or DoDelete, one resource accepts
GET, POST, PUT or DELETE requests.
The following code gives an example of HelloWorldResource, which can be visited by sending a GET request to "/hello-world", and respones a plain string in code "2.05 Content".
class HelloWorldResource : Resource
{
public HelloWorldResource()
: base("hello-world")
{
Attributes.Title = "GET a friendly greeting!";
}
protected override void DoGet(CoapExchange exchange)
{
exchange.Respond("Hello World from CoAP.NET!");
}
}
class Server
{
static void Main(String[] args)
{
CoapServer server = new CoapServer();
server.Add(new HelloWorldResource());
server.Start();
}
}
See for more.
Logging makes use of the Microsoft.Extensions.Logging package.
Logging is configured using the static LogManager class. By default, logs will be output to the console. A custom logger
can be specified by calling LogManager.SetLoggerFactory(ILoggerFactory) as follows:
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
LogManager.SetLoggerFactory(loggerFactory);
The project is built using Visual Studio 2022. The project is set up to use the latest .NET framework (version 7.0 as of this writing). The project can be built direction in Visual Studio or via the the command line as follows:
> dotnet build
BSD with attribution See for more info.
This project is built on the CoAP-CSharp project of jimsch and the CoAP.NET
project of smeshlink (which in turn is based on Eclipse Californium). This is a refresh of the original codebases as they were both no longer being maintained.
The package and class names have been reset to the original names per the CoAP.NET project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on CoAP.NET:
| Package | Downloads |
|---|---|
|
Chaosage.Core.Setup
Chaosage开发平台API配置规范 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.5-pre-9 | 271 | 10/16/2024 |
| 1.0.5-pre-8 | 426 | 12/19/2023 |
| 1.0.5-pre-7 | 249 | 12/18/2023 |
| 1.0.4 | 3,228 | 7/11/2023 |
| 1.0.4-pre-7 | 223 | 12/18/2023 |
| 1.0.4-pre-6 | 205 | 12/18/2023 |
| 1.0.4-pre | 197 | 12/18/2023 |
| 1.0.3 | 494 | 6/5/2023 |
| 1.0.2 | 297 | 6/2/2023 |
| 1.0.1 | 306 | 5/30/2023 |
| 1.0.0 | 526 | 5/26/2023 |
This project is built on the CoAP-CSharp project of jimsch and the CoAP.NET project of smeshlink (which in turn is based on Californium). This is a refresh of the original codebases as they were both no longer being maintained. The package and class names have been reset to the original names per the CoAP.NET project.
1.0.4
- Logging fixes and improvements
1.0.3
- Fixed a bug on the client side which prevented DTLS connections from being established
1.0.2
- Refactored logging to use Microsoft.Extensions.Logging (see README for usage details)
1.0.1
- Removed dependency on Com.AugustCellars.COSE; currently only DTLS with pre-shared keys (PSK) is supported
1.0.0
- Intial refresh of project codebase