DTLS 0.5.1
dotnet add package DTLS --version 0.5.1
NuGet\Install-Package DTLS -Version 0.5.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DTLS" Version="0.5.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DTLS" Version="0.5.1" />
<PackageReference Include="DTLS" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DTLS --version 0.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DTLS, 0.5.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DTLS@0.5.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DTLS&version=0.5.1
#tool nuget:?package=DTLS&version=0.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DTLS
High-performance DTLS (Datagram Transport Layer Security) library for .NET.
Usage
datagrams is an IDatagramTransport for one peer. Use cancellationToken to cancel the operations.
Client
using DTLS.Dtls;
using System.Text;
DtlsClientOptions options = new() { ServerName = "example.com" };
using DtlsTransport client = await DtlsTransport.CreateClientAsync(datagrams, options, cancellationToken);
await client.HandshakeAsync(cancellationToken);
await client.SendAsync("Hello, DTLS!"u8.ToArray(), cancellationToken);
byte[] buffer = new byte[65536];
int length = await client.ReceiveAsync(buffer, cancellationToken);
Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, length));
await client.CloseAsync(cancellationToken);
Server certificates are validated during the handshake. Set RemoteCertificateValidation to customize validation.
Server
using DTLS.Dtls;
DtlsServerOptions options = new() { Certificate = serverCertificate };
using DtlsTransport server = await DtlsTransport.CreateServerAsync(datagrams, options, cancellationToken);
await server.HandshakeAsync(cancellationToken);
byte[] buffer = new byte[65536];
int length = await server.ReceiveAsync(buffer, cancellationToken);
if (length > 0)
{
await server.SendAsync(buffer.AsMemory(0, length), cancellationToken);
}
await server.CloseAsync(cancellationToken);
serverCertificate must contain an exportable ECDSA private key.
Dispose the underlying transport and supplied certificates yourself.
API
| Type | Purpose |
|---|---|
| DtlsTransport | Asynchronous handshake, send, receive, and close operations. |
| DtlsSession | Protocol processing when you manage I/O and timers yourself. |
| IDatagramTransport | Transport interface that preserves datagram boundaries. |
| DtlsClientOptions | Server name and optional client certificate. |
| DtlsServerOptions | Server certificate and client authentication. |
| DtlsVersion | Protocol versions for MinVersion and MaxVersion. |
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DTLS:
| Package | Downloads |
|---|---|
|
Stun.Net
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on DTLS:
| Repository | Stars |
|---|---|
|
HMBSbige/NatTypeTester
测试当前网络的 NAT 类型(STUN)
|