Class Server
- Namespace
- IceRpc
- Assembly
- IceRpc.dll
A server accepts connections from clients and dispatches the requests it receives over these connections.
public sealed class Server : IAsyncDisposable
- Inheritance
-
Server
- Implements
- Inherited Members
Constructors
Server(IDispatcher, ServerAddress, SslServerAuthenticationOptions?, IDuplexServerTransport?, IMultiplexedServerTransport?, ILogger?)
Constructs a server with the specified dispatcher, server address and authentication options. All other properties use the ServerOptions defaults.
public Server(IDispatcher dispatcher, ServerAddress serverAddress, SslServerAuthenticationOptions? serverAuthenticationOptions = null, IDuplexServerTransport? duplexServerTransport = null, IMultiplexedServerTransport? multiplexedServerTransport = null, ILogger? logger = null)
Parameters
dispatcher
IDispatcherThe dispatcher of the server.
serverAddress
ServerAddressThe server address of the server.
serverAuthenticationOptions
SslServerAuthenticationOptionsThe SSL server authentication options. When not null, the server will accept only secure connections.
duplexServerTransport
IDuplexServerTransportThe transport used to create ice protocol connections. null is equivalent to Default.
multiplexedServerTransport
IMultiplexedServerTransportThe transport used to create icerpc protocol connections. null is equivalent to Default.
logger
ILogger
Server(IDispatcher, SslServerAuthenticationOptions?, IDuplexServerTransport?, IMultiplexedServerTransport?, ILogger?)
Constructs a server with the specified dispatcher and authentication options. All other properties use the ServerOptions defaults.
public Server(IDispatcher dispatcher, SslServerAuthenticationOptions? serverAuthenticationOptions = null, IDuplexServerTransport? duplexServerTransport = null, IMultiplexedServerTransport? multiplexedServerTransport = null, ILogger? logger = null)
Parameters
dispatcher
IDispatcherThe dispatcher of the server.
serverAuthenticationOptions
SslServerAuthenticationOptionsThe SSL server authentication options. When not null, the server will accept only secure connections.
duplexServerTransport
IDuplexServerTransportThe transport used to create ice protocol connections. null is equivalent to Default.
multiplexedServerTransport
IMultiplexedServerTransportThe transport used to create icerpc protocol connections. null is equivalent to Default.
logger
ILogger
Server(IDispatcher, Uri, SslServerAuthenticationOptions?, IDuplexServerTransport?, IMultiplexedServerTransport?, ILogger?)
Constructs a server with the specified dispatcher, server address URI and authentication options. All other properties use the ServerOptions defaults.
public Server(IDispatcher dispatcher, Uri serverAddressUri, SslServerAuthenticationOptions? serverAuthenticationOptions = null, IDuplexServerTransport? duplexServerTransport = null, IMultiplexedServerTransport? multiplexedServerTransport = null, ILogger? logger = null)
Parameters
dispatcher
IDispatcherThe dispatcher of the server.
serverAddressUri
UriA URI that represents the server address of the server.
serverAuthenticationOptions
SslServerAuthenticationOptionsThe SSL server authentication options. When not null, the server will accept only secure connections.
duplexServerTransport
IDuplexServerTransportThe transport used to create ice protocol connections. null is equivalent to Default.
multiplexedServerTransport
IMultiplexedServerTransportThe transport used to create icerpc protocol connections. null is equivalent to Default.
logger
ILogger
Server(ServerOptions, IDuplexServerTransport?, IMultiplexedServerTransport?, ILogger?)
Constructs a server.
public Server(ServerOptions options, IDuplexServerTransport? duplexServerTransport = null, IMultiplexedServerTransport? multiplexedServerTransport = null, ILogger? logger = null)
Parameters
options
ServerOptionsThe server options.
duplexServerTransport
IDuplexServerTransportThe transport used to create ice protocol connections. The null value is equivalent to Default.
multiplexedServerTransport
IMultiplexedServerTransportThe transport used to create icerpc protocol connections. The null value is equivalent to Default.
logger
ILogger
Methods
DisposeAsync()
Releases all resources allocated by this server. The server stops listening for new connections and disposes the connections it accepted from clients.
public ValueTask DisposeAsync()
Returns
- ValueTask
A value task that completes when the disposal of all connections accepted by the server has completed. This includes connections that were active when this method is called and connections whose disposal was initiated prior to this call.
Remarks
The disposal of an underlying connection of the server aborts invocations, cancels dispatches and disposes the underlying transport connection without waiting for the peer. To wait for invocations and dispatches to complete, call ShutdownAsync(CancellationToken) first. If the configured dispatcher does not complete promptly when its cancellation token is canceled, the disposal can hang.
Listen()
Starts accepting connections on the configured server address. Requests received over these connections are then dispatched by the configured dispatcher.
public ServerAddress Listen()
Returns
- ServerAddress
The server address this server is listening on and that a client would connect to. This address is the same as the ServerAddress of ServerOptions except its Transport property is always non-null and its port number is never 0 when the host is an IP address.
Remarks
Listen() can also throw exceptions from the transport; for example, the transport can reject the server address.
Exceptions
- IceRpcException
Thrown when the server transport fails to listen on the configured ServerAddress.
- InvalidOperationException
Thrown when the server is already listening, shut down or shutting down.
- ObjectDisposedException
Throw when the server is disposed.
ShutdownAsync(CancellationToken)
Gracefully shuts down this server: the server stops accepting new connections and shuts down gracefully all its connections.
public Task ShutdownAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA cancellation token that receives the cancellation requests.
Returns
- Task
A task that completes successfully once the shutdown of all connections accepted by the server has completed. This includes connections that were active when this method is called and connections whose shutdown was initiated prior to this call. This task can also complete with one of the following exceptions:
- IceRpcException with error OperationAborted if the server is disposed while being shut down.
- OperationCanceledException if cancellation was requested through the cancellation token.
- TimeoutException if the shutdown timed out.
Exceptions
- InvalidOperationException
Thrown if this method is called more than once.
- ObjectDisposedException
Thrown if the server is disposed.
ToString()
Returns a string that represents this server.
public override string ToString()
Returns
- string
A string that represents this server.