Documentation

Datagram Options

Read time 2 minutes Package: Nalix.Network
On this page

DatagramOptions (public sealed partial class DatagramOptions : ConfigurationLoader, IValidatableConfiguration, namespace Nalix.Network.Options) holds the settings of the Datagram Listener. The per-session settings (channels, idle timeout, message size, buffers) are in DatagramEngineOptions (Nalix.Environment.Options).

Source Mapping

  • src/Nalix.Network/Options/DatagramOptions.cs
  • src/Nalix.Network/Listeners/Datagram/DatagramListener.Core.cs
  • src/Nalix.Network/Listeners/Datagram/DatagramListener.SocketConfig.cs
  • src/Nalix.Environment/Options/DatagramEngineOptions.cs

Options

PropertyTypeDefaultValidationUsed for
TicketLifetimeSecondsint10[ValueRange(1, 300)]Seconds within which the first datagram of a ticket must arrive; also advertised to the client as DatagramTicketInfo.ExpiresInSeconds.
MaxSessionsint100_000[ValueRange(1, int.MaxValue)]Largest number of established sessions plus pending tickets; IssueTicket throws InvalidOperationException beyond it.
ReceiveWorkersint1[ValueRange(1, 64)]Number of workers reading the UDP socket.
SocketReceiveBufferSizeint4194304 (4 MiB)[ValueRange(65_536, int.MaxValue)]UDP socket ReceiveBufferSize.
SocketSendBufferSizeint4194304 (4 MiB)[ValueRange(65_536, int.MaxValue)]UDP socket SendBufferSize.

Validate() runs DataAnnotation validation (this.ValidateDataAnnotations()) and throws ValidationException when a constraint fails. DatagramListener validates both DatagramOptions and DatagramEngineOptions in its constructor.

Configuration

The class is loaded through ConfigurationManager.Instance.Get<DatagramOptions>() and written into server.ini by the hosting bootstrap (Bootstrap.cs). Its INI section comment reads “Datagram listener (NDP over UDP) — tickets, session limit and socket buffers”.

using Nalix.Hosting;
using Nalix.Hosting.Protocols;
using Nalix.Network.Options;

NetworkApplication app = NetworkApplication.CreateBuilder()
    .Configure<DatagramOptions>(opt =>
    {
        opt.ReceiveWorkers = 4;
        opt.MaxSessions = 20_000;
    })
    .UseSecureConnections()
    .MapTcp<DefaultProtocol>().OnPort(57206).Bind()
    .MapDatagram<DefaultProtocol>().OnPort(57207).Bind()
    .Build();

Operational Guidance

  • Raise ReceiveWorkers only when a single worker cannot drain the socket; each worker owns a pinned buffer of DatagramEngine.MaxDatagramSize + 1 (1473) bytes.
  • Keep TicketLifetimeSeconds short: a pending ticket keeps the session secret in memory until it is promoted, replaced or swept.
  • MaxSessions counts pending tickets as well, so a client that requests tickets without using them can only hold one per stream connection (a new request replaces the old ticket).
  • The shared socket policy (EnableDualStack, DualMode) comes from Network Socket Options; the socket buffer sizes do not.