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
andClient
.- 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
, aService
and aClient
. The member names and JSON datatype for each network device is described below.-
- 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 NetworkManager
provides. Users who are an administrator of the NetworkManager
can request private attributes, seeadmin_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 allClient
devices that are currently connected to the NetworkManager
.- services: object
An object (a Python
dict
) of allService
devices that are currently connected to the NetworkManager
.
-
- 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 theService
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 namedadd_integers
that takes parameters namedx
andy
as integer inputs and returns an integer, and a method namedscalar_multiply
that takes parameters nameda
as a floating-point number anddata
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
Client
s that can be linked with theService
. If the value is \(\leq\) 0 then that means that an unlimited number ofClient
s can be linked (this is the default setting if max_clients is not specified).
-
- 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.
-
- class msl.network.network.Device(name=None)[source]
Bases:
Network
Base class for a
Service
andClient
.New in version 1.0.
- Parameters:
name (
str
, optional) – The name of the device as it will appear on the NetworkManager
. If not specified then the class name is used.
- 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 port
The port number of this device that is being used for the connection to the
Manager
.- Type:
- 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.