SetNet.Priority 1.1.0

dotnet add package SetNet.Priority --version 1.1.0
                    
NuGet\Install-Package SetNet.Priority -Version 1.1.0
                    
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="SetNet.Priority" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.Priority" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.Priority" />
                    
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 SetNet.Priority --version 1.1.0
                    
#r "nuget: SetNet.Priority, 1.1.0"
                    
#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 SetNet.Priority@1.1.0
                    
#: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=SetNet.Priority&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.Priority&version=1.1.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.Priority

Priority send queue for SetNet.

When a connection is saturated, not all messages are equally important. A hit confirmation or a chat line matters more than the umpteenth position update. PrioritySender is a per-connection outbound queue: during a tick you enqueue messages with a numeric priority, then flush — the queue drains highest-priority-first. An optional per-flush byte budget lets low-priority traffic defer under load; whatever doesn't fit stays queued for the next flush (natural back-pressure). That budget is the hook that pairs with SetNet.Congestion.

Added by composition — construct one over a client or a peer, no base class.

Install

dotnet add package SetNet
dotnet add package SetNet.Priority

Usage

Payloads are sent already-serialized (raw), so serialize once and enqueue the bytes.

var sender = new PrioritySender(client);   // or new PrioritySender(peer)

// during your tick — enqueue serialized payloads with a priority (higher = sent sooner):
sender.Enqueue((ushort)MsgType.Hit,
               SetNetSerializer.Serialize(hit),
               priority: 100, DeliveryMethod.Reliable);

sender.Enqueue((ushort)MsgType.Position,
               SetNetSerializer.Serialize(pos),
               priority: 10,  DeliveryMethod.Unreliable);

// flush everything, highest-priority-first:
int sent = await sender.FlushAsync();

// …or flush within a byte budget — the rest stays queued for next tick:
int sentThisTick = await sender.FlushAsync(maxBytes: 30_000);

// inspect back-pressure:
Console.WriteLine($"still queued: {sender.QueuedBytes} bytes");

API

Member Purpose
new PrioritySender(BaseClient client) wrap a client's raw send path
new PrioritySender(BasePeer peer) wrap a server peer's raw send path
void Enqueue(ushort type, byte[] payload, int priority, DeliveryMethod delivery = Reliable) queue an already-serialized message; higher priority is sent first
Task<int> FlushAsync(int? maxBytes = null) send highest-priority-first, return the count sent; with a budget, stop once maxBytes payload bytes are sent and leave the rest queued
int QueuedBytes total bytes currently queued across all priorities

Combining Priority + Congestion

PrioritySender supplies the ordering and the back-pressure knob; SetNet.Congestion supplies the number — a target send rate that adapts to acks and losses. Feed the controller's per-tick budget straight into FlushAsync:

var sender = new PrioritySender(client);
var cc     = new CongestionController(startRate: 128_000);   // 128 KB/s

// from your own ack/loss tracking:
void OnAck()  => cc.OnDelivered();   // additive increase
void OnDrop() => cc.OnLoss();        // multiplicative decrease

const double tickRate = 30.0;        // ticks/sec

// each tick:
sender.Enqueue((ushort)MsgType.Hit,      SetNetSerializer.Serialize(hit), priority: 100);
sender.Enqueue((ushort)MsgType.Position, SetNetSerializer.Serialize(pos), priority: 10, DeliveryMethod.Unreliable);

int budget = cc.BudgetForInterval(1.0 / tickRate);
await sender.FlushAsync(budget);      // high-priority goes first; low-priority defers when the rate is low

Under congestion the rate falls, the budget shrinks, and low-priority messages naturally back up (visible via QueuedBytes) while the important ones keep flowing.

Notes

  • Ordering is by priority, then FIFO within a priority. Same-priority messages flush in enqueue order.
  • Always sends at least one. A flush with a budget will send at least the top item even if it exceeds the budget, so a single large high-priority message never stalls forever.
  • Sends are raw (SendRawAsync) — serialize with SetNetSerializer (or your own serializer) before enqueuing.
  • Not a transport. It sits on top of SetNet's normal send path and works over any transport (TCP / UDP / Both / WebSockets); DeliveryMethod is honored per message as usual.

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

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.1.0 151 7/2/2026