narupa.app.app_server module

Module providing an out-of-the-box Narupa application server, with an underyling gRPC server, discovery, multiplayer and commands.

class narupa.app.app_server.NarupaApplicationServer(server: narupa.core.narupa_server.NarupaServer, discovery: Optional[narupa.essd.server.DiscoveryServer] = None, name: Optional[str] = None)

Bases: object

Provides a convenient Narupa server for typical applications, with local area network discovery provided by ESSD, multiplayer configuration and a command service.

Use this a base for building specific applications by inheriting from it and attaching additional services.

DEFAULT_SERVER_NAME = 'Narupa Server'
add_service(service)

Adds a gRPC service to the server and broadcast it on discovery. :param service: Service implementation

address

Address of the server. :return: Address of the server.

classmethod basic_server(name: Optional[str] = None, address: Optional[str] = None, port: Optional[int] = None)

Initialises a basic Narupa application server with default settings, with a default unencrypted server and ESSD discovery server for finding it on a local area network.

Parameters:
  • name – Name of the server for the purposes of discovery.
  • address – The address at which to bind the server to. If none given, the default address of
  • port – Optional port on which to run the Narupa server. If none given, default port will be used.
Returns:

An instantiation of a basic Narupa server, registered with an ESSD discovery server.

close()

Close the application server and all services.

discovery

The discovery service that can be used to allow clients to find services hosted by this application. :return: The discovery service, or None if no discovery has been set up.

Services added directly to the server running on this application via :fun:`NarupaApplicationServer.add_service` are automatically added to this discovery service.

Accessing the discovery service directly enables one to register their own server that may be running separately to the core application.

name

Name of the server. :return: The name of the server.

port

Server port. :return: Port of the server.

running_discovery

Indicates whether a discovery service is running or not. :return: True if discovery is available, False otherwise.

server

The underlying Narupa server for this application. One can use this to manage commands and services. :return: The Narupa server.

class narupa.app.app_server.SupportsClose(*args, **kwargs)

Bases: typing_extensions.Protocol

close() → None
narupa.app.app_server.qualified_server_name(base_name: str)

Prefixes the given server name with identifying information of the machine running it.

narupa.app.app_server.start_default_server_and_discovery(address: Optional[str] = None, port: Optional[int] = None) → Tuple[narupa.core.narupa_server.NarupaServer, narupa.essd.server.DiscoveryServer]

Utility method for creating a default Narupa server along with ESSD discovery.

Param:address: Address to run the server at. If nothing is passed, the default address of all interfaces will be used.
Param:port: Port to run the server on, if nothing is passed, the default Narupa port will be used. The value of zero should be passed to let the OS pick a free port.
Returns:tuple of Narupa server and ESSD discovery.