nanover.app.app_server module

Module providing an out-of-the-box NanoVer application server supporting all the standard features.

class nanover.app.app_server.NanoverApplicationServer(*, discovery: DiscoveryServer | None = None, name: str | None = None, address: str | None = None)

Bases: object

Provides a convenient NanoVer 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: str = 'NanoVer Server'
add_service(name: str, port: int)
property address

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

classmethod basic_server(*, name: str | None = None, address: str | None = None)

Initialises a basic NanoVer 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

Returns:

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

clear_locks()

Forces the release all locks on all keys in the shared key/value store.

close()

Close the application server and all services.

property commands

Gets the commands available on this server.

Returns:

The commands, consisting of their names, callback and default parameters.

copy_state()

Return a shallow copy of the current state.

property 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 NanoverApplicationServer.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.

property frame_publisher

The frame publisher attached to this application. Use it to publish frames for consumption by NanoVer frame clients.

Returns:

The FramePublisher attached to this application.

lock_state()

Context manager for reading the current state while delaying any changes to it.

property name

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

classmethod null_server()
register_command(name: str, callback: Callable[[...], dict | None] | Callable[[], dict | None], default_arguments: dict | None = None)

Adds a command on this server.

Parameters:
  • name – Name of the command to register

  • callback – Method to be called whenever the given command name is run by a client.

  • default_arguments – A description of the arguments of the callback and their default values.

Raises:

ValueError – Raised when a command with the same name already exists.

run_command(name: str, arguments: dict[str, Any])
property running_discovery

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

property service_hub
property state_dictionary
unregister_command(name)

Deletes a command from this server.

Parameters:

name – Name of the command to delete

update_state(access_token: Any, change: DictionaryChange)

Attempts an atomic update of the shared key/value store. If any key cannot be updates, no change will be made.

nanover.app.app_server.qualified_server_name(base_name: str)

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