metalTools.ConnectionManagement.NetMq
26.10.11.1
dotnet add package metalTools.ConnectionManagement.NetMq --version 26.10.11.1
NuGet\Install-Package metalTools.ConnectionManagement.NetMq -Version 26.10.11.1
<PackageReference Include="metalTools.ConnectionManagement.NetMq" Version="26.10.11.1" />
<PackageVersion Include="metalTools.ConnectionManagement.NetMq" Version="26.10.11.1" />
<PackageReference Include="metalTools.ConnectionManagement.NetMq" />
paket add metalTools.ConnectionManagement.NetMq --version 26.10.11.1
#r "nuget: metalTools.ConnectionManagement.NetMq, 26.10.11.1"
#:package metalTools.ConnectionManagement.NetMq@26.10.11.1
#addin nuget:?package=metalTools.ConnectionManagement.NetMq&version=26.10.11.1
#tool nuget:?package=metalTools.ConnectionManagement.NetMq&version=26.10.11.1
metalTools.ConnectionManagement.NetMq
Optional .NET 10 NetMQ connection lifecycle package for Windows and Linux. Install this package explicitly; the transport-independent metalTools convenience package does not pull in NetMQ.
NetMqRequestChannel owns each REQ socket on one worker thread, serializes string-frame requests, observes transport connect/disconnect events, bounds queueing and request time, and recreates the socket after incomplete exchanges. Cancellation or timeout never replays a command: a timed-out write may already have executed.
Implement INetMqSessionProtocol for your application's wire format. Its handshake must verify the application/protocol and return a SessionLease; heartbeat must reject invalid tokens. Use the same channel for management and application requests. Transport connectivity is diagnostic only; a successful application heartbeat determines health.
NetMqSessionDiscovery.FindAsync(host, range, protocol, hello) scans a metalTools.PortDiscovery.TcpPortRange, limits concurrent probes, retains the verified winner and disposes losers. Closed ports return null; protocol mismatches throw SessionRejectedException; cancellation propagates. Use short handshake request deadlines (for example 250 ms on loopback).
var hello = new SessionHello(stableClientId, "viewer", "MyApp/1");
await using var connection = new NetMqConnectionSupervisor(
ct => NetMqSessionDiscovery.FindAsync("127.0.0.1", new(51200, 51299), protocol, hello, cancellationToken: ct));
await connection.RunAsync(stoppingToken);
Alternatively call UpdateAsync from your host's timer or loop. Discovery is attempted immediately, then every five seconds while unavailable. Heartbeats occur at most every five seconds and at least three times per lease duration. After a failed command call DisconnectAsync; use RetryAsync for an explicit retry. A new handshake is required for every reconnect, including server restarts. A stable client ID replaces its old registration; each connection receives a new token. Poll State, CurrentSession and LastError for health/UI state. Keep long application calls shorter than the lease or extend the lease: serialized REQ traffic cannot send a heartbeat during another request.
NetMqReplyChannel binds on the constructing host thread, polls without blocking, and requires one reply per request. It disposes only its own socket, preserving other NetMQ hosts in the process. The host calls its receive/reply methods and disposal on that same thread.
On the server, attach SessionRegistry to your existing REP owner-thread dispatcher. Register a validated hello, renew matching tokens, release on graceful disconnect, and call Expire() periodically even without traffic. Its returned snapshots identify resources the application should reclaim. GetSnapshot() exposes active clients for health reporting. Expiry uses monotonic time; UTC timestamps are informational. Server instance IDs and per-session tokens prevent stale renewals/releases from touching replacement sessions. Lease IDs are correlation tokens, not authentication credentials. The registry defaults to a configurable 1024-client limit; call Expire periodically to reclaim slots. Authenticate separately for untrusted networks.
The registry deliberately does not dispatch application work or start a server thread: game and UI hosts can preserve thread affinity. Hosts own shutdown cancellation and must await channel/supervisor disposal. Dispose server sockets on their owner thread. Do not call process-wide NetMQ cleanup while other hosts still use NetMQ.
PortDiscovery remains independent: generic address/range utilities and bounded asynchronous endpoint scanning belong there; NetMQ socket ownership and session policy belong here. See LiveUi.Client/LiveUi.Server for an adapter over an existing application protocol.
| 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. |
-
net10.0
- metalTools.PortDiscovery (>= 26.10.11.1)
- NetMQ (>= 4.0.4.3)
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 |
|---|---|---|
| 26.10.11.1 | 130 | 10/11/2026 |
| 26.10.10.1232 | 146 | 10/10/2026 |