Table of Contents

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 IDispatcher

The dispatcher of the server.

serverAddress ServerAddress

The server address of the server.

serverAuthenticationOptions SslServerAuthenticationOptions

The SSL server authentication options. When not null, the server will accept only secure connections.

duplexServerTransport IDuplexServerTransport

The transport used to create ice protocol connections. null is equivalent to Default.

multiplexedServerTransport IMultiplexedServerTransport

The transport used to create icerpc protocol connections. null is equivalent to Default.

logger ILogger

The logger. null is equivalent to Instance.

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 IDispatcher

The dispatcher of the server.

serverAuthenticationOptions SslServerAuthenticationOptions

The SSL server authentication options. When not null, the server will accept only secure connections.

duplexServerTransport IDuplexServerTransport

The transport used to create ice protocol connections. null is equivalent to Default.

multiplexedServerTransport IMultiplexedServerTransport

The transport used to create icerpc protocol connections. null is equivalent to Default.

logger ILogger

The logger. null is equivalent to Instance.

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 IDispatcher

The dispatcher of the server.

serverAddressUri Uri

A URI that represents the server address of the server.

serverAuthenticationOptions SslServerAuthenticationOptions

The SSL server authentication options. When not null, the server will accept only secure connections.

duplexServerTransport IDuplexServerTransport

The transport used to create ice protocol connections. null is equivalent to Default.

multiplexedServerTransport IMultiplexedServerTransport

The transport used to create icerpc protocol connections. null is equivalent to Default.

logger ILogger

The logger. null is equivalent to Instance.

Server(ServerOptions, IDuplexServerTransport?, IMultiplexedServerTransport?, ILogger?)

Constructs a server.

public Server(ServerOptions options, IDuplexServerTransport? duplexServerTransport = null, IMultiplexedServerTransport? multiplexedServerTransport = null, ILogger? logger = null)

Parameters

options ServerOptions

The server options.

duplexServerTransport IDuplexServerTransport

The transport used to create ice protocol connections. The null value is equivalent to Default.

multiplexedServerTransport IMultiplexedServerTransport

The transport used to create icerpc protocol connections. The null value is equivalent to Default.

logger ILogger

The logger. null is equivalent to Instance.

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 CancellationToken

A 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:

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.