Network Socket Options

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

Namespace: Nalix.Network.Options
Assembly: Nalix.Network

NetworkSocketOptions (public sealed partial class NetworkSocketOptions : ConfigurationLoader, IValidatableConfiguration) configures the shared socket policy used by TcpListenerBase, UdpListenerBase, and SocketUdpTransport.

Source Mapping

  • src/Nalix.Network/Options/NetworkSocketOptions.cs
  • src/Nalix.Network/Listeners/TcpListener/TcpListener.Core.cs
  • src/Nalix.Network/Listeners/TcpListener/TcpListener.SocketConfig.cs
  • src/Nalix.Network/Listeners/TcpListener/TcpListener.ProcessChannel.cs
  • src/Nalix.Network/Listeners/UdpListener/UdpListener.Core.cs
  • src/Nalix.Network/Listeners/UdpListener/UdpListener.SocketConfig.cs
  • src/Nalix.Network/Listeners/UdpListener/UdpListener.Receive.cs
  • src/Nalix.Network/Internal/Transport/SocketUdpTransport.cs

Defaults and Validation

Loaded from the [NetworkSocket] section of default.ini:

PropertyTypeDefaultValidationRuntime Effect
Portushort57206[ValueRange(1, 65535)]; setter throws ArgumentOutOfRangeException if < 1Default TCP/UDP listening port when no explicit port is passed to the listener constructor.
Backlogint512[ValueRange(1, 65535)]Passed to Socket.Listen(Backlog) on TCP listeners.
EnableTimeoutbooltrue—Enables registering/unregistering accepted TCP connections with the shared TimingWheel.
EnableDualStackbooltrue—Binds an IPv6 (AddressFamily.InterNetworkV6) listener socket (with automatic IPv4 fallback if unsupported).
DualModebooltrue—Sets Socket.DualMode = true on IPv6 listener sockets so both IPv6 and IPv4-mapped connections are accepted on the same port.
NoDelaybooltrue—Sets Socket.NoDelay = true on accepted TCP sockets (disables Nagle’s algorithm).
MaxParallelint1[ValueRange(1, 1024)]Number of concurrent SAEA TCP accept workers scheduled at listener activation (and multiplier for preallocating accept pools).
MaxParallelUDPint1[ValueRange(1, 1024)]Number of concurrent SAEA UDP receive worker loops scheduled at activation.
BufferSizeint65536[ValueRange(2048, 10_485_760)]Applied to TCP listener ReceiveBufferSize, accepted TCP client SendBufferSize/ReceiveBufferSize, and UDP SendBufferSize/ReceiveBufferSize.
KeepAlivebooltrue—Enables TCP Keep-Alive probes (TcpKeepAliveTime = 3s, TcpKeepAliveInterval = 1s, TcpKeepAliveRetryCount = 3, with Windows IOControlCode.KeepAliveValues fallback).
ReuseAddressbooltrue—Sets ExclusiveAddressUse = !ReuseAddress and SocketOptionName.ReuseAddress.
ReusePortbooltrue—Attempts to enable SO_REUSEPORT (SocketOptionName.ReuseUnicastPort) where supported by the OS.
TcpFastOpenbooltrue—Attempts to enable TCP_FASTOPEN on the listening socket where supported by the OS.
DispatchProcessorAffinityint-1—0-based CPU core index used to pin the TCP accept-channel consumer thread (-1 leaves OS default scheduling).
ProcessChannelCapacityint256[ValueRange(1, int.MaxValue)]Capacity of the bounded Channel<AcceptConnectionResult> between TCP accept workers and the initialization consumer.
ProcessChannelDrainTimeoutint5000[ValueRange(0, 60000)]Maximum milliseconds to wait for the TCP accept process channel to drain gracefully during Deactivate.
MaxUdpDatagramSizeint1440[ValueRange(64, 65507)]Maximum allowed size in bytes for a single inbound (UdpListenerBase) or outbound (SocketUdpTransport) UDP datagram.

Validate() runs this.ValidateDataAnnotations() and throws ValidationException when any [ValueRange] constraint fails.

TCP vs. UDP Socket Application

SettingApplied to TcpListenerBaseApplied to UdpListenerBase / SocketUdpTransport
Port, EnableDualStack, DualMode, BufferSize, ReuseAddress, ReusePortYesYes
Backlog, NoDelay, KeepAlive, TcpFastOpen, EnableTimeout, MaxParallel, DispatchProcessorAffinity, ProcessChannelCapacity, ProcessChannelDrainTimeoutYesNo
MaxParallelUDP, MaxUdpDatagramSize, DontFragment = true, Windows SIO_UDP_CONNRESET suppressionNoYes