StellaOps.Router.Transport.Udp.Server
Router UDP transport, server side: the datagram listener a gateway receives microservice frames with.
| Package | StellaOps.Router.Transport.Udp.Server |
| Component | Router |
| Licence | BUSL-1.1 (Router licence) |
| Package kind | Library |
| Target framework | net10.0 |
To add the package to a project, see Installing Stella Ops packages.
Namespaces
| Namespace | Types |
|---|---|
StellaOps.Router.Transport.Udp.Server | 3 |
StellaOps.Router.Transport.Udp.Server namespace
| Type | Kind | Description |
|---|---|---|
UdpTransportServer | class | UDP transport server implementation for the gateway. |
UdpTransportServerPlugin | class | Plugin for the server side of the UDP transport, which a gateway listens with. |
UdpTransportServerServiceCollectionExtensions | class | Extension methods for registering the server side of the UDP transport. |
UdpTransportServer class
public sealed class UdpTransportServer : IGatewayConnectionTransportServer, IAsyncDisposable
UDP transport server implementation for the gateway. UDP transport is stateless - connections are logical based on source endpoint.
UdpTransportServer(IOptions<UdpTransportOptions>, ILogger<UdpTransportServer>) constructor
public UdpTransportServer(IOptions<UdpTransportOptions> options, ILogger<UdpTransportServer> logger)
Initializes a new instance of the UdpTransportServerclass.
ConnectionCount property
public int ConnectionCount { get; }
Gets the number of active connections.
TransportType property
public TransportType TransportType { get; }
The transport this server provides.
OnConnection event
public event Action<string, ConnectionState>? OnConnection
Event raised when a connection is established (on first HELLO).
OnDisconnection event
public event Action<string>? OnDisconnection
Event raised when a connection is lost.
OnFrame event
public event Action<string, Frame>? OnFrame
Event raised when a frame is received.
CloseConnection(string) method
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.
DisposeAsync() method
public ValueTask DisposeAsync()
See IAsyncDisposable.DisposeAsync().
GetConnectionState(string) method
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.
GetConnections() method
public IEnumerable<ConnectionState> GetConnections()
Gets all active connections.
RemoveConnection(string) method
public void RemoveConnection(string connectionId)
Removes a connection (for cleanup purposes).
Parameters
connectionId: The connection ID.
SendFrameAsync(string, Frame, CancellationToken) method
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.
StartAsync(CancellationToken) method
public Task StartAsync(CancellationToken cancellationToken)
Starts listening for incoming connections.
Parameters
cancellationToken: Cancellation token.
StopAsync(CancellationToken) method
public Task StopAsync(CancellationToken cancellationToken)
Stops accepting new connections.
Parameters
cancellationToken: Cancellation token.
UdpTransportServerPlugin class
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.
UdpTransportServerPlugin() constructor
public UdpTransportServerPlugin()
Creates an instance of UdpTransportServerPlugin.
DisplayName property
public string DisplayName { get; }
Gets the human-readable display name for this transport.
Mode property
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)).
TransportName property
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.
Register(RouterTransportRegistrationContext) method
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.
UdpTransportServerServiceCollectionExtensions class
public static class UdpTransportServerServiceCollectionExtensions
Extension methods for registering the server side of the UDP transport.
AddUdpTransportServer(IServiceCollection, Action<UdpTransportOptions>) extension method
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.
