msl.network.network module
Base classes for a Manager,
Service and Client.
- class msl.network.network.Network[source]
Bases:
objectBase class for the
Manager,ServiceandClient.- 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, aServiceand aClient. The member names and JSON datatype for each network device is described below.-
- hostname: string
The name of the computer that the Network
Manageris running on.- port: integer
The port number that the Network
Manageris running on.- attributes: object
An object (a Python
dict) of public attributes that the NetworkManagerprovides. Users who are an administrator of the NetworkManagercan request private attributes, seeadmin_request().- language: string
The programming language that the Network
Manageris running on.- os: string
The name of the operating system that the Network
Manageris running on.- clients: object
An object (a Python
dict) of allClientdevices that are currently connected to the NetworkManager.- services: object
An object (a Python
dict) of allServicedevices 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 theServiceprovides. 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
pithat takes no inputs and returns a floating-point number, a method namedadd_integersthat takes parameters namedxandyas integer inputs and returns an integer, and a method namedscalar_multiplythat takes parameters namedaas a floating-point number anddataas 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
Clientknow 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
Serviceis running on.- os: string, optional
The name of the operating system that the
Serviceis running on.- max_clients: integer, optional
The maximum number of
Clients that can be linked with theService. If the value is \(\leq\) 0 then that means that an unlimited number ofClients 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
Clientis running on.- os: string, optional
The name of the operating system that the
Clientis running on.
- Returns:
dict– The identity of the network device.
-
- class msl.network.network.Device(name=None)[source]
Bases:
NetworkBase class for a
ServiceandClient.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
Noneif 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.