StellaOps.Router.Transport.Udp.Server

Router UDP transport, server side: the datagram listener a gateway receives microservice frames with.

library
Component
Router
Licence
BUSL-1.1 (Router licence)
Target framework
net10.0
Latest release
1.0.1-20261117T070237Z

Install

dotnet add package StellaOps.Router.Transport.Udp.Server --version 1.0.1-20261117T070237Z

Namespaces

NamespaceTypes
StellaOps.Router.Transport.Udp.Server3

namespace StellaOps.Router.Transport.Udp.Server

TypeKindDescription
UdpTransportServerclassUDP transport server implementation for the gateway.
UdpTransportServerPluginclassPlugin for the server side of the UDP transport, which a gateway listens with.
UdpTransportServerServiceCollectionExtensionsclassExtension methods for registering the server side of the UDP transport.

class UdpTransportServer

public sealed class UdpTransportServer : IGatewayConnectionTransportServer, IAsyncDisposable

UDP transport server implementation for the gateway. UDP transport is stateless - connections are logical based on source endpoint.

Members

MemberKindSummary
UdpTransportServer(IOptions<UdpTransportOptions>, ILogger<UdpTransportServer>)constructorInitializes a new instance of the UdpTransportServerclass.
ConnectionCountpropertyGets the number of active connections.
TransportTypepropertyThe transport this server provides.
OnConnectioneventEvent raised when a connection is established (on first HELLO).
OnDisconnectioneventEvent raised when a connection is lost.
OnFrameeventEvent raised when a frame is received.
CloseConnection(string)methodCloses a connection.
DisposeAsync()methodSee IAsyncDisposable.DisposeAsync().
GetConnectionState(string)methodGets the connection state by ID.
GetConnections()methodGets all active connections.
RemoveConnection(string)methodRemoves a connection (for cleanup purposes).
SendFrameAsync(string, Frame, CancellationToken)methodSends a frame to a connection.
StartAsync(CancellationToken)methodStarts listening for incoming connections.
StopAsync(CancellationToken)methodStops accepting new connections.

constructor UdpTransportServer(IOptions<UdpTransportOptions>, ILogger<UdpTransportServer>) #

public UdpTransportServer(IOptions<UdpTransportOptions> options, ILogger<UdpTransportServer> logger)

Initializes a new instance of the UdpTransportServerclass.

property ConnectionCount #

public int ConnectionCount { get; }

Gets the number of active connections.

property TransportType #

public TransportType TransportType { get; }

The transport this server provides.

event OnConnection #

public event Action<string, ConnectionState>? OnConnection

Event raised when a connection is established (on first HELLO).

event OnDisconnection #

public event Action<string>? OnDisconnection

Event raised when a connection is lost.

event OnFrame #

public event Action<string, Frame>? OnFrame

Event raised when a frame is received.

method CloseConnection(string) #

public bool CloseConnection(string connectionId)

Closes a connection.

Parameters

  • connectionId: The connection identifier.

Returns

true when the connection existed and was closed.

Remarks

UDP has no session to close: the logical connection is forgotten and UdpTransportServer.OnDisconnectionis raised. A later HELLO from the same peer registers it again.

method DisposeAsync() #

public ValueTask DisposeAsync()

See IAsyncDisposable.DisposeAsync().

method GetConnectionState(string) #

public ConnectionState? GetConnectionState(string connectionId)

Gets the connection state by ID.

Parameters

  • connectionId: The connection ID.

Returns

The connection state, or null if not found.

method GetConnections() #

public IEnumerable<ConnectionState> GetConnections()

Gets all active connections.

method RemoveConnection(string) #

public void RemoveConnection(string connectionId)

Removes a connection (for cleanup purposes).

Parameters

  • connectionId: The connection ID.

method SendFrameAsync(string, Frame, CancellationToken) #

public Task SendFrameAsync(string connectionId, Frame frame, CancellationToken cancellationToken = default)

Sends a frame to a connection.

Parameters

  • connectionId: The connection ID.
  • frame: The frame to send.
  • cancellationToken: Cancellation token.

method StartAsync(CancellationToken) #

public Task StartAsync(CancellationToken cancellationToken)

Starts listening for incoming connections.

Parameters

  • cancellationToken: Cancellation token.

method StopAsync(CancellationToken) #

public Task StopAsync(CancellationToken cancellationToken)

Stops accepting new connections.

Parameters

  • cancellationToken: Cancellation token.

class UdpTransportServerPlugin

public sealed class UdpTransportServerPlugin : IRouterTransportPlugin

Plugin for the server side of the UDP transport, which a gateway listens with. The client side is UdpTransportPluginin StellaOps.Router.Transport.Udp; both carry the transport name udp.

Members

MemberKindSummary
UdpTransportServerPlugin()constructorCreates an instance of UdpTransportServerPlugin.
DisplayNamepropertyGets the human-readable display name for this transport.
ModepropertyGets the side of the transport this plugin registers: RouterTransportMode.Client, RouterTransportMode.Server, or RouterTransportMode.Both.
TransportNamepropertyGets the transport name (e.g., “tcp”, “tls”, “udp”, “rabbitmq”, “inmemory”, “messaging”), shared by the client and the server plugin of one transport.
Register(RouterTransportRegistrationContext)methodRegisters transport services into the DI container for the side the context asks for.

constructor UdpTransportServerPlugin() #

public UdpTransportServerPlugin()

Creates an instance of UdpTransportServerPlugin.

property DisplayName #

public string DisplayName { get; }

Gets the human-readable display name for this transport.

property Mode #

public RouterTransportMode Mode { get; }

Gets the side of the transport this plugin registers: RouterTransportMode.Client, RouterTransportMode.Server, or RouterTransportMode.Both. IRouterTransportPlugin.Register(RouterTransportRegistrationContext)refuses a context that asks for a side outside this value (RouterTransportRegistrationContext.EnsureSupportedBy(IRouterTransportPlugin)).

property TransportName #

public string TransportName { get; }

Gets the transport name (e.g., “tcp”, “tls”, “udp”, “rabbitmq”, “inmemory”, “messaging”), shared by the client and the server plugin of one transport.

method Register(RouterTransportRegistrationContext) #

public void Register(RouterTransportRegistrationContext context)

Registers transport services into the DI container for the side the context asks for.

Parameters

  • context: The registration context containing services, configuration, and transport mode.

Exceptions

  • InvalidOperationException: The context asks for a side this plugin does not provide.

class UdpTransportServerServiceCollectionExtensions

public static class UdpTransportServerServiceCollectionExtensions

Extension methods for registering the server side of the UDP transport.

Members

MemberKindSummary
AddUdpTransportServer(IServiceCollection, Action<UdpTransportOptions>)extension methodAdds UDP transport server services to the service collection.

extension method AddUdpTransportServer(IServiceCollection, Action<UdpTransportOptions>) #

public static IServiceCollection AddUdpTransportServer(this IServiceCollection services, Action<UdpTransportOptions>? configure = null)

Adds UDP transport server services to the service collection.

Parameters

  • services: The service collection.
  • configure: Optional configuration action.

Returns

The service collection.