Hello World sample application in Python
Description
This Hello World application written in Python uses two agents, a publisher and a subscriber, to pass and print a Hello World string.
Design
The Hello World application comprises two agents: helloPub and helloSub. helloPub instantiates a stringMsg object and populates it with "Hello World!" and then publishes the object once a second. helloSub subscribes to the stringMsg object and prints the contents of stringMsg to the screen.

Create Project
Create a project in Distrix System Builder.
Import Agent and Object Definitions
Copy the following JSON format agent and object definitions into a text file and save it.
[
{
"build_system": null,
"protocol_configs":
[
{
"protocol": "Local",
"key": "key.pem",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"serverPort": "23000",
"memSize": "16777216"
},
{
"protocol": "TCP",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"key": "key.pem",
"targets": [{"ip": "127.0.0.1", "port": "21000"}]
},
{
"protocol": "IP",
"localPort": "22000",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"key": "key.pem",
"multicastPort": "22001",
"multicastGroup": "239.0.1.2"
}
],
"description": "",
"parent_chain": [],
"timing_interval": "1000",
"subscriptions": [],
"languages": ["c#", "python", "c", "java", "c++"],
"publications": [{"path": "/Data/", "save_type": 0, "type": "stringMsg", "name": null}],
"type": "agent",
"name": "helloPub"
},
{
"build_system": null,
"protocol_configs":
[
{
"protocol": "Local",
"key": "key.pem",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"serverPort": "23000",
"memSize": "16777216"
},
{
"protocol": "TCP",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"key": "key.pem",
"targets": [{"ip": "127.0.0.1", "port": "21000"}]
},
{
"protocol": "IP",
"localPort": "22000",
"certificate": "cert.pem",
"cas": "CAs.pem",
"encrypted": 0,
"key": "key.pem",
"multicastPort": "22001",
"multicastGroup": "239.0.1.2"
}
],
"description": "",
"parent_chain": [],
"timing_interval": "1000",
"subscriptions":
[
{
"name": null,
"creation_callback": true,
"deletion_callback": true,
"orphanage_callback": false,
"adoption_callback": false,
"path": "/Data/",
"type": "stringMsg",
"change_callback": true
}
],
"languages": ["c#", "python", "c", "java", "c++"],
"publications": [],
"type": "agent",
"name": "helloSub"
},
{
"methods": [],
"parent_chain": [],
"fields":
[
{
"instance_name": "strMsg",
"type": ["primitive", "string"]
}
],
"distributed": true,
"type": "object",
"name": "stringMsg"
}
]
Import the saved agent and object definitions into your Distrix System Builder project using the File|Import function. Importing the definitions into Distrix System Builder creates two agents and one object:
- helloPub - Publishes the content of stringMsg in a timing action which is set to repeat once every second (1000ms).
- helloSub - Subscribes to stringMsg. In this case, no timing action is needed; helloSub's actions are instead based on a change in the subscribed object.
- stringMsg - object having a single string variable strMsg which acts as the container for "Hello World!".
One publication and one subscription are created. Review the agent and object definitions in Distrix System Builder. Use the Graphical View to view the system diagram.
- Publications
- helloPub - stringMsg
- Subscriptions
-
helloSub - stringMsg
-
Generate the code
Generate the code using the Distrix System Builder Project|Generate Code... function.
Add software code
Add code to populate stringMsg and display it. In this example the code is Python. Code that must be added to helloPubImpl.py and helloSubImpl.py is shown below.


