LAN.Lib 1.1.51

This package has a SemVer 2.0.0 package version: 1.1.51+7bcb272e6a0ab068789cf0e7f9aad37efab4b139.
There is a newer version of this package available.
See the version list below for details.
dotnet add package LAN.Lib --version 1.1.51
                    
NuGet\Install-Package LAN.Lib -Version 1.1.51
                    
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="LAN.Lib" Version="1.1.51" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LAN.Lib" Version="1.1.51" />
                    
Directory.Packages.props
<PackageReference Include="LAN.Lib" />
                    
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 LAN.Lib --version 1.1.51
                    
#r "nuget: LAN.Lib, 1.1.51"
                    
#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 LAN.Lib@1.1.51
                    
#: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=LAN.Lib&version=1.1.51
                    
Install as a Cake Addin
#tool nuget:?package=LAN.Lib&version=1.1.51
                    
Install as a Cake Tool

LAN.Lib

Zero-dependency LAN peer discovery for .NET: a symmetric UDP announce beacon plus a self-expiring peer table, over a single shared broadcast domain, filtered by service name. TimeProvider-driven (so beacon cadence and expiry are deterministic in tests), AOT/trim friendly, with a one-line DI extension for the .NET generic host.

Extracted and generalised from the LAN-play discovery in the chess project.

What it does

  • Symmetric discovery. Every node broadcasts a small ASCII announce beacon (1 s) and listens for everyone else's, keeping a live table of peers that self-expires (5 s) when a node goes quiet. Both cadences run off an injected TimeProvider.
  • One shared broadcast domain. All apps broadcast on one UDP port (52821) with one magic prefix; a consumer filters to the service it cares about (IPeerTable.PeersOf("...")). ReuseAddress lets several apps share the port on one host — no port-per-app.
  • Stable node identity. A node can mint a persisted node id once (StableNodeIdPath) and advertise it in every beacon, so a consumer can bind to a node and recognise it across restarts even as its address changes. Separate from the per-process peer id, which exists only to filter a node's own beacon echo.
  • Extensible. The announce carries an open key=value property bag (URL-encoded values), so an app can advertise extra facts — a version, a capability flag — with no wire-format bump.
  • Foreign-datagram safe. A magic + version prefix means a datagram that isn't ours (or is malformed) is ignored, never misparsed — the shared port coexists with anything else on it.

Discovery is UDP-only by design: its whole job is to tell an app which address:port to open a session/control channel to (TCP, WebSocket, HTTP, …). That channel is the app's concern.

Usage

using LAN.Lib;

// On a node that others discover and bind to (e.g. a headless server):
services.AddLanDiscovery(o =>
{
    o.ServiceName = "tianwen-server";                 // announced + filtered on
    o.ServicePort = 1888;                             // the port peers should reach us at
    o.NodeName = Environment.MachineName;             // human display name
    o.StableNodeIdPath = Path.Combine(appData, "node-id.txt"); // mint-once, persisted
});

// On a consumer that only wants to see who's out there (never appears itself):
services.AddLanDiscovery(o =>
{
    o.ServiceName = "tianwen-gui";
    o.Announce = false;                               // listen-only
});

// Anywhere, read the live peer list (a fresh snapshot each call; Changed hints when to re-read):
IPeerTable peers = provider.GetRequiredService<IPeerTable>();
foreach (var peer in peers.PeersOf("tianwen-server"))
    Console.WriteLine($"{peer.DisplayName} @ {peer.EndPoint}  (node {peer.NodeId})");

AddLanDiscovery registers ILanTransport (via TryAdd, so a bespoke/fake transport can be registered first), the LanDiscovery beacon + peer table (as IPeerTable), and a hosted service that runs them for the host's lifetime (sending a polite bye on shutdown).

Testing

LanDiscovery needs no host and no real sockets: construct it directly with an in-memory ILanTransport and a FakeTimeProvider, then Advance the clock to drive beacon cadence and expiry deterministically. See src/LAN.Lib.Tests.

License

MIT — see LICENSE.

Product 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.

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.2.101 69 8/20/2026
1.2.91 211 8/4/2026
1.2.81 65 8/2/2026
1.1.61 45 8/2/2026
1.1.51 229 7/25/2026
1.1.31 28 7/24/2026
1.1.21 30 7/24/2026
1.0.11 32 7/23/2026