Real-time bidirectional networking for .NET. Source-generated hubs and proxies with zero reflection, multiple transports, and full AOT compatibility.
| Name | NuGet | Description |
|---|---|---|
NexNet |
Core library for server and client communication. | |
NexNet.Generator |
Source generator for hubs and proxies. | |
NexNet.Quic |
QUIC transport support. | |
NexNet.Asp |
ASP.NET Core integration for WebSocket and HttpSocket transports. |
NexNet is a networking framework for .NET that handles bidirectional communication between servers and clients. A Roslyn source generator emits all hub and proxy code at compile time — there is no reflection, no runtime code generation, and the result is fully NativeAOT compatible.
Interfaces define the contract between server and client. The generator produces strongly-typed proxies, invocation dispatchers, and serialization code. At runtime, connecting and invoking methods is straightforward: start a server, connect a client, and call methods through the proxy. NexNet handles reconnection, multiplexing, and transport abstraction.
Beyond RPC, NexNet provides synchronized collections that keep data in sync across server and clients, duplex pipes for raw byte streaming, typed channels for structured data streaming, and a declarative authorization system — all source-generated with the same zero-reflection approach.
| Capability | NexNet | SignalR | gRPC |
|---|---|---|---|
| Source generated (no reflection) | Yes | No | Yes (protobuf) |
| Bidirectional RPC | Yes | Yes (hub methods) | Yes (streams) |
| Transport options | 6 (UDS, TCP, TLS, QUIC, WS, HttpSocket) | 3 (WS, SSE, Long Polling) | 1 (HTTP/2) |
| Synchronized collections | Yes | No | No |
| Duplex byte streaming | Yes (pipes + channels) | Yes (streams) | Yes (streams) |
| Auto reconnection | Yes | Yes | No |
| Built-in rate limiting | Yes | No | No |
| NativeAOT compatible | Yes | No | Partial |
| Session groups | Yes | Yes | No |
| Interface versioning | Yes (hash-locked) | No | Yes (protobuf) |
| ASP.NET integration | Yes | Native | Native |
- Source-generated hubs and proxies — all invocation code emitted at compile time; no reflection
- Bidirectional method invocation — server-to-client and client-to-server calls with void, ValueTask, and ValueTask<T> returns
- Synchronized collections — INexusList with server-to-client, bidirectional, and relay modes
- Duplex pipes — bidirectional byte streaming with built-in congestion control
- Typed channels — INexusDuplexChannel<T> and INexusDuplexUnmanagedChannel<T> with IAsyncEnumerable support
- Session management — per-session hub instances, named groups for targeted broadcasting, automatic reconnection
- Authentication — token-based connection authentication with IIdentity
- Authorization — declarative
[NexusAuthorize<TPermission>]with caching and compile-time diagnostics - Interface versioning — version hierarchy with HashLock validation and runtime enforcement
- Six transports — UDS, TCP, TLS, QUIC, WebSocket, HttpSocket
- ASP.NET Core integration — middleware with DI, authentication, and reverse proxy support
- Rate limiting — per-IP limits, sliding windows, and automatic banning
- Benchmarks — ~27,000 invocations/sec with minimal allocations
// Shared interfaces
public interface IClientNexus
{
ValueTask<string> GetUserName();
}
public interface IServerNexus
{
ValueTask<int> GetStatus(int userId);
}
// Client nexus
[Nexus<IClientNexus, IServerNexus>(NexusType = NexusType.Client)]
partial class ClientNexus
{
public ValueTask<string> GetUserName()
=> new("Bill");
}
// Server nexus
[Nexus<IServerNexus, IClientNexus>(NexusType = NexusType.Server)]
partial class ServerNexus
{
public ValueTask<int> GetStatus(int userId)
=> new(1);
}
// Usage
var server = ServerNexus.CreateServer(serverConfig, () => new ServerNexus());
var client = ClientNexus.CreateClient(clientConfig, new ClientNexus());
await server.StartAsync();
await client.ConnectAsync();
var status = await client.Proxy.GetStatus(42);The generator emits all hub and proxy classes at compile time. See Getting Started for the full walkthrough.
BenchmarkDotNet v0.15.8, Windows 11 (10.0.26100.7462/24H2/2024Update/HudsonValley)
Intel Core i7-10700 CPU 2.90GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK 9.0.305
[Host] : .NET 9.0.9 (9.0.9, 9.0.925.41916), X64 RyuJIT x86-64-v3
Job-FJSVHN : .NET 9.0.9 (9.0.9, 9.0.925.41916), X64 RyuJIT x86-64-v3
Platform=X64 Runtime=.NET 9.0
| Method | Mean | Error | StdDev | Op/s | Allocated |
|---|---|---|---|---|---|
| InvocationNoArgument | 36.7 us | 0.33 us | 0.31 us | 27,241.7 | 595 B |
| InvocationUnmanagedArgument | 37.4 us | 0.52 us | 0.48 us | 26,769.8 | 649 B |
| InvocationUnmanagedMultipleArguments | 37.3 us | 0.28 us | 0.25 us | 26,800.8 | 700 B |
| InvocationNoArgumentWithResult | 36.9 us | 0.35 us | 0.32 us | 27,095.2 | 633 B |
| InvocationWithDuplexPipe_Upload | 51.8 us | 0.60 us | 0.51 us | 19,295.4 | 14,951 B |
| Scenario | Recommended Transport | Reason |
|---|---|---|
| Same machine IPC | Unix Domain Sockets | Highest performance, no network overhead |
| Local network | TCP | Simple, reliable, fast |
| Internet/WAN | TLS over TCP | Secure, widely supported |
| Mobile/unstable networks | QUIC | Connection migration, better congestion control |
| Web applications | WebSockets | Browser compatibility, firewall-friendly |
| Reverse proxy setups | HttpSockets | Lower overhead than WebSockets |
- MemoryPack for message serialization.
- Internally packages Marc Gravell's Pipelines.Sockets.Unofficial with additional performance modifications for pipeline socket transports.
- QUIC transport requires
libmsquicon Linux. Windows Support
| Sample | Description |
|---|---|
NexNetDemo |
Console app demonstrating invocations, channels, duplex pipes, collections, and API versioning |
NexNetSample.Asp |
ASP.NET Core server and client with HttpSocket transport, bearer auth, duplex pipes, and collections |