DataChannelDotnet 1.1.2

dotnet add package DataChannelDotnet --version 1.1.2
                    
NuGet\Install-Package DataChannelDotnet -Version 1.1.2
                    
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="DataChannelDotnet" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DataChannelDotnet" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="DataChannelDotnet" />
                    
Project file
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 DataChannelDotnet --version 1.1.2
                    
#r "nuget: DataChannelDotnet, 1.1.2"
                    
#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 DataChannelDotnet@1.1.2
                    
#: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=DataChannelDotnet&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=DataChannelDotnet&version=1.1.2
                    
Install as a Cake Tool

DataChannelDotnet - C# WebRtc library

Run .NET Tests Update libdatachannel NuGet NuGet

DataChannelDotnet is a high performance, minimal overhead wrapper around libdatachannel for WebRtc, it supports both datachannels and media tracks. Raw bindings are generated automatically via clangsharp using Github Actions, and are included in the DataChannel.Bindings package.

Usage (Managed version)

IRtcPeerConnection host = new RtcPeerConnection(new RtcPeerConfiguration()
{
    IceServers = ["stun:stun.l.google.com:19302"]
});

IRtcPeerConnection client = new RtcPeerConnection(new RtcPeerConfiguration()
{
    IceServers = ["stun:stun.l.google.com:19302"]
});

host.OnConnectionStateChange += (_, state) => Console.WriteLine($"Host connection state -> {state}");
client.OnConnectionStateChange += (_, state) => Console.WriteLine($"Client connection state -> {state}");

host.OnCandidateSafe += (_, candidate) => client.AddRemoteCandidate(candidate);
client.OnCandidateSafe += (_, candidate) => host.AddRemoteCandidate(candidate);

host.OnLocalDescriptionSafe += (_, description) => client.SetRemoteDescription(description);
client.OnLocalDescriptionSafe += (_, description) => host.SetRemoteDescription(description);

client.OnDataChannel += (_, channel) =>
{
    channel.OnTextReceivedSafe += (dataChannel, data) =>
    {
        Console.WriteLine($"Client: received '{data.Text}'");
    };
};

var hostChannel = host.CreateDataChannel(new RtcCreateDataChannelArgs()
{
    Label = "testchannel1"
});

hostChannel.OnOpen += channel =>
{
    channel.Send("Hello :)");
};

Raw C bindings can also be used via the static Rtc class in DataChannel.Bindings. Check the C API Documentation from Libdatachannel for usage. Note that using the raw bindings will require unsafe code to be enabled in your project.

Logging

You can enable Libdatachannel log output by calling RtcLog.Initialize(level, callback);

Unhandled exceptions

If an unhandled exception is thrown on an RtcThread callback, RtcTools.UnhandledException will be raised.

Performance

This is a thin wrapper, so the performance should be very close to the native Libdatachannel library. Sending & receiving data (via Track or Datachannel) is entirely allocation free.

Here is the results of a throughput benchmark, sending & receiving data on localhost, running on .net 9 on a Ryzen 5500. This shows around 55-60MB/s throughput, which is consistent with Libdatachannels own benchmark. This also shows zero allocation sending & receiving. It should be noted that WebRtc is generally not designed for large file transfer scenarios.

Method Mean Error StdDev Allocated
SendAndReceive100MB 1,728.885 ms 12.9256 ms 12.0906 ms -
SendAndReceive50MB 849.148 ms 11.5134 ms 10.7696 ms -
SendAndReceive1MB 16.517 ms 0.3237 ms 0.3854 ms -
SendAndReceive256KB 3.818 ms 0.1247 ms 0.3657 ms -
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 67 8/1/2025
1.1.1 90 7/30/2025