SquidStd.Network
Networking primitives for SquidStd: TCP and UDP servers and clients with per-connection sessions, a pluggable framing + middleware pipeline, span-based binary readers/writers, and a circular buffer - designed for low-allocation, high-throughput byte processing.
Install
dotnet add package SquidStd.Network
Usage
using System.Net;
using SquidStd.Network.Server;
await using var server = new SquidTcpServer(new IPEndPoint(IPAddress.Any, 9000));
await server.StartAsync(CancellationToken.None);
// ... server.IsRunning, server.Port ...
await server.StopAsync(CancellationToken.None);
Key types
| Type | Purpose |
|---|---|
INetworkServer |
TCP/UDP server contract (StartAsync/StopAsync). |
INetworkConnection |
A single client connection. |
ISessionManager<TState> |
Tracks sessions and their typed state. |
INetFramer |
Splits the byte stream into messages. |
INetMiddleware |
Pipeline stage over inbound/outbound data. |
SpanReader / SpanWriter |
Allocation-free binary read/write. |
Related
- Tutorial: Networking
License
MIT - part of SquidStd.
The receive pipeline
flowchart LR
Bytes[Raw bytes] --> MW1[Middleware 1]
MW1 --> MW2[Middleware N]
MW2 --> Framing[INetFramer<br/>frame extraction]
Framing --> Handler[Message handler]
Handler -->|response| Out[Write pipeline]
Each connection runs inbound bytes through the middleware chain (INetMiddleware), then the configured INetFramer splits the accumulated stream into discrete frames before they reach your handler. The write path runs the same middleware chain on outgoing payloads before the bytes hit the socket.