Skip to content

Quickstart

Peer-to-Peer Messaging with hyveOS

Hello World Setup Quickstart Setup. Two Raspberry Pi 5s with hyveOS installed.
Neither is connected to the Internet.

Peer-to-peer messaging is a fundamental building block of decentralized applications.

Prerequisite

Make sure you have access to two machines, from now on called node0 and node1, having installed hyveOS. It can your robots.

Also, be sure that all of your docker permissions are set up correctly. E.g., per usual, the user on the node needs permission to talk to the Docker daemon through the Unix socket.

Hello World

Now that hyveOS is installed, we are ready to do some application development. In this introductory Hello World Quick Start, we focus on you understanding how to deploy and run an application and to get a feeling for the effects of hyveOS. We will:

  1. Deploy a containerized decentral application from node0 to both node0 and node1
  2. Observe a simple peer-to-peer message exchange between the nodes

Deploying the application

We will leverage hyveOS application distribution system and will start the Hello World application for both nodes from node0. For this, we will need the ID of node1 as well as the Hello World application, which, for the sake of this Quickstart, we already built for you to download on node0.

Identify node1

To get node1’s id, run the following on node1

Terminal window
hyvectl whoami

Copy the <ID>.

Pull the Docker image

Pull our pre-built Hello-World application only to node0. Run on node0

Terminal window
docker pull ghcr.io/p2p-industries/hyveos-hello_world:latest

Deploy the Application to both nodes

We are now using hyvectl to deploy the Hello World application to both nodes only from node0.

As initial deployment can take a few seconds, you want to begin with deploying to node 1, from node0.

To deploy and start the application on node1 through node 0, run on node0 first:

Terminal window
hyvectl hyve start ghcr.io/p2p-industries/hyveos-hello_world:latest <ID>

where <ID> is the ID of node1, you copied from the previous step.

To then start the application on node0, run on node0

Terminal window
hyvectl hyve start ghcr.io/p2p-industries/hyveos-hello_world:latest

Output

That’s it! You have successfully used hyveOS to send messages from node 1 to node 0 and vice versa. hyveOS took care of distributing and starting the application automatically.

You should now see the communication between the nodes in both terminals using the appropriate Docker commands.

If you want to dive deeper into the code and understand application, or need to see commands for viewing the output, check out the Hello World Full Tutorial.

Terminate the Loop

What does the application do?

Hello World Code
main.py
import asyncio
from hyveos_sdk import Connection
async def wait_for_peers(discovery):
await asyncio.sleep(5)
async for event in discovery.discovery_events():
if event is not None:
print(f"Discovered a peer: {event}")
break
async def node(topic):
print("--- APPLICATION SCRIPT is RUNNING ---")
async with Connection() as connection:
discovery = connection.get_discovery_service()
gossip_sub = connection.get_gossip_sub_service()
own_id = await discovery.get_own_id()
print(f"Node {own_id} has started.")
while True:
await wait_for_peers(discovery)
stream = await gossip_sub.subscribe(topic)
await asyncio.sleep(12)
message = f"Hello from {own_id}"
await gossip_sub.publish(message, topic)
async for msg in stream:
if msg != message:
print(f"Node {own_id} received: {msg}")
break
async def main():
topic = "greetings"
await node(topic)
if __name__ == "__main__":
asyncio.run(main())

node 0 will discover node 1 and vice versa. Once they have found each other, they both subscribe to the topic greetings. Everyone subscribed to greetings will receive all the messages someone else sends into the topic—our decentralized pub-sub system will take care of that.

Both nodes will periodically send the message Hello from <own_node_id> into greetings and each will receive and print the message of the form Hello from <other_node_id> from the other one.

Note the loop in the node function. You will see a bunch of messages.


© 2025 P2P Industries. This documentation is licensed under the MIT License.
Cookie Policy    Privacy Policy