msl.network.network module

Base classes for a Manager, Service and Client.

class msl.network.network.Network[source]

Bases: object

Base class for the Manager, Service and Client.

identity() dict[source]

The identity of a device on the network.

All devices on the network must be able to identify themselves to any other device that is connected to the network. There are 3 possible types of network devices – a Manager, a Service and a Client. The member names and JSON datatype for each network device is described below.

  • Manager

    hostname: string

    The name of the computer that the Network Manager is running on.

    port: integer

    The port number that the Network Manager is running on.

    attributes: object

    An object (a Python dict) of public attributes that the Network Manager provides. Users who are an administrator of the Network Manager can request private attributes, see admin_request().

    language: string

    The programming language that the Network Manager is running on.

    os: string

    The name of the operating system that the Network Manager is running on.

    clients: object

    An object (a Python dict) of all Client devices that are currently connected to the Network Manager.

    services: object

    An object (a Python dict) of all Service devices that are currently connected to the Network Manager.

  • Service

    type: string

    This must be equal to 'service' (case-insensitive).

    name: string

    The name to associate with the Service (can contain spaces).

    attributes: object

    An object (a Python dict) of the attributes that the Service provides. The keys are the method names and the values are the method signatures (expressed as a string).

    The attributes get populated automatically when subclassing Service. If you are creating a Service in another programming language then you can use the following as an example for how to define an attributes object:

    {
      "pi": "() -> float",
      "add_integers": "(x:int, y:int) -> int",
      "scalar_multiply": "(a:float, data:List[floats]) -> List[floats]"
    }
    

    This Service would provide a method named pi that takes no inputs and returns a floating-point number, a method named add_integers that takes parameters named x and y as integer inputs and returns an integer, and a method named scalar_multiply that takes parameters named a as a floating-point number and data as an array of floating-point numbers as inputs and returns an array of floating-point numbers.

    The key must be equal to the name of the method that the Service provides; however, the value (the method signature) is only used as a helpful guide to let a Client know what the method takes as inputs and what the method returns. How you express the method signature is up to you. The above example could also be expressed as:

    {
      "pi": "() -> 3.1415926...",
      "add_integers": "(int32 x, int32 y) -> x+y",
      "scalar_multiply": "(double a, *double data) -> *double"
    }
    
    language: string, optional

    The programming language that the Service is running on.

    os: string, optional

    The name of the operating system that the Service is running on.

    max_clients: integer, optional

    The maximum number of Clients that can be linked with the Service. If the value is \(\leq\) 0 then that means that an unlimited number of Clients can be linked (this is the default setting if max_clients is not specified).

  • Client

    type: string

    This must be equal to 'client' (case-insensitive).

    name: string

    The name to associate with the Client (can contain spaces).

    language: string, optional

    The programming language that the Client is running on.

    os: string, optional

    The name of the operating system that the Client is running on.

Returns:

dict – The identity of the network device.

static set_logging_level(level: str | int) bool[source]

Set the logging level.

Parameters:

level (int or str) – The logging level of the msl.network logger.

Returns:

bool – Whether setting the logging level was successful.

class msl.network.network.Device(name=None)[source]

Bases: Network

Base class for a Service and Client.

New in version 1.0.

Parameters:

name (str, optional) – The name of the device as it will appear on the Network Manager. If not specified then the class name is used.

property address_manager

The address of the Manager that this device is connected to.

Type:

str

property loop_thread_id

Identifier of the thread running the event loop.

Returns None if the event loop is not running.

New in version 1.0.

property name

The name of the device on the Manager.

Type:

str

property port

The port number of this device that is being used for the connection to the Manager.

Type:

int

add_tasks(*coros_or_futures)[source]

Additional tasks to run in the event loop.

New in version 1.0.

Parameters:

coros_or_futures – Coroutines or futures that will be passed to asyncio.gather() when the event loop runs.

shutdown_handler()[source]

Called after the connection to the Network Manager has been lost but before the event loop stops.

Override this method to do any necessary cleanup.

New in version 1.0.