SpawnDev.WebTorrent

Pure C# BitTorrent/WebTorrent client and server for desktop and browser.

License: MITnet10.0

SpawnDev.WebTorrent is a pure C# BitTorrent/WebTorrent client and server with no JavaScript dependencies. The same library and API run on desktop .NET and in Blazor WebAssembly, using SpawnDev.RTC for WebRTC peer connections so browser and desktop peers interoperate. It implements 18 BEPs, including BEP 52 v2 and hybrid torrents.

Runs on

Blazor WebAssembly (browser)Desktop .NET (Windows, WPF, console)

Highlights

  • Desktop and browser from one API (WPF, console, Blazor WebAssembly), with real WebRTC P2P through SpawnDev.RTC.
  • 18 BEPs including DHT, Fast Extension, ut_metadata, ut_pex, private torrents, tracker scrape, local service discovery and BEP 52 (SHA-256 / Merkle v2 and hybrid v1+v2 torrents).
  • Media streaming with seeking: a shipped service worker serves video/audio range requests from pieces on demand; file.CreateReadStream() returns a seekable .NET Stream.
  • Persistent storage in OPFS (browser) or the filesystem (desktop); torrents resume after reload.
  • .torrent creation and parsing, web seed (BEP 17/19) download, seeding with rate limiting and a bandwidth policy setting.
  • Optional HuggingFace server extension that proxies the HuggingFace model CDN with local caching and automatic torrent generation.
  • Custom wire extensions via UseExtension() and BEP 46 mutable items with Ed25519 signing for agent communication.
Program.cs
// Any page or service - inject the singleton
@inject WebTorrentClient Client

// Download a torrent
var torrent = await Client.AddAsync("magnet:?xt=urn:btih:...");

// Stream a video with seeking
var url = torrent.Files[0].StreamURL;
// <video src="@url" controls></video>

// Or set directly on an element
torrent.Files[0].StreamTo(videoElement);

// Get a .NET Stream
using var stream = torrent.Files[0].CreateReadStream();
var buffer = new byte[4096];
var bytesRead = await stream.ReadAsync(buffer);
stream.Position = 1000000; // seek
bytesRead = await stream.ReadAsync(buffer);

// Seed data
var seeded = await Client.SeedAsync(myBytes, "model.onnx");
Console.WriteLine(seeded.MagnetURI);

Install

dotnet add package SpawnDev.WebTorrent
dotnet add package SpawnDev.WebTorrent.Server
dotnet add package SpawnDev.WebTorrent.Server.HuggingFace

Building on SpawnDev.WebTorrent?

Private tickets, response targets and a direct line to the engineer who wrote it.

See support plans
An unhandled error has occurred. Reload x