This guide explains how to implement peer-to-peer (node-to-node) communication in Hyperware applications.
DO NOT use WebSockets for node-to-node real-time updates. Hyperware has its own internal P2P messaging system. WebSocket endpoints in the hyperprocess macro are not yet functional and should not be relied upon.
For real-time game updates (e.g., player joins, moves, state changes):
- Use Hyperware's Request API to send messages between nodes
- Implement polling on the client side if needed
- Use the fire-and-forget pattern (shown below) for broadcasting updates
When making remote calls, use the string format and parse it:
let publisher = "hpn-testing-beta.os";
let target_process_id_str = format!("process_name:package_name:{}", publisher);
let target_process_id = target_process_id_str.parse::<ProcessId>()
.map_err(|e| format!("Failed to parse ProcessId: {}", e))?;let target_address = Address::new(remote_node_name, target_process_id);For remote calls, use the Request API directly with JSON-wrapped payloads:
let request_wrapper = json!({
"RemoteMethodName": parameters
});
let result = Request::new()
.target(target_address)
.body(serde_json::to_vec(&request_wrapper).unwrap())
.expects_response(30) // CRITICAL: Always set timeout for remote calls
.send_and_await_response(30).unwrap();For notifications that don't need responses:
let _ = Request::new()
.target(target_address)
.body(request_body)
.expects_response(30) // Still set this for reliability
.send();The generated caller_utils use a send function that may not properly set expects_response. For reliable remote communication, consider using the direct Request API as shown above.
- "Failed to deserialize" errors: Usually means the ProcessId format is incorrect
- No response from remote node: Ensure
expects_responseis set - Connection failures: Verify both nodes are running and the node names are correct (e.g., "alice.os", "bob.os")
- Run two instances of your app on different nodes
- Use the actual node names (not "placeholder.os") when testing
- Check logs on both nodes to debug communication issues