← All Workshops

MudEngine Part 11: Peer-to-Peer with iroh

Step 13 / 14

Run it!

You need at least two terminals. The host starts first; the client joins with the node id the host shows.

Both commands are long-running desktop sessions — start the host, note the node id in its banner, then start the client and paste it.

Terminal 1: compile once
cargo check
Terminal 2: host — owns the world
cargo run
Terminal 3: join as a second player
cargo run
🎭 Two-player test (same machine)
  1. Terminal 2 — Alice (host): cargo run, name "Alice", Host a game. A banner appears: 🖥️ Hosting. Share your node id so friends can join: followed by the node id.
  2. Terminal 3 — Bob (client): cargo run, name "Bob", Join a game (copy-paste Alice's full node id), Enter.
  3. Both windows reach the game screen within moments — mDNS resolves the peer, or the relay bridges it, depending on your network.
  4. Move Bob east into the hall; Alice sees him land there. Descend-only checks still rule: without two heroes on the pedestals the vault stays sealed, and the King's dialog updates as the portal opens.
  5. Kill Bob's process (Ctrl-C). Within a second Alice's roster drops Bob, his carried items land on his room's floor, and — if that completes a quest condition — the quest UI updates. That cleanup is NeighborDown → engine.leave(), the piece that had no analog in the Axum server.

To test across two machines, run the same two commands; Bob needs Alice's node id (works over LAN with mDNS, over the internet through the relay).

🚦 Troubleshooting

endpoint bind failed / address in use → another MudEngine (or a leftover test) still holds a port. The key file host.secret is persistent: delete it only if you deliberately want a new host identity.

Join hangs on "Connecting to the mesh…" → the client never reached the host. Check: the host is actually running, host.secret made its node id stable, and you pasted the whole node id. On a multi-interface workstation make sure endpoint.online() ran (it is in connect() before the session returns) — this is the fix that un-stuck the LAN mesh on a machine with a pile of docker bridges.

Host prints, then dies a moment later → you (or an earlier hand-copied version) dropped the Router guard. The Router handle must stay alive; review the tokio::spawn(async move { let _router = router; …}) block.

error[E0275] at build → the stylo patch isn't in place (see the Cargo.toml step). You need third_party/stylo + the [patch.crates-io] section.

Test process hangs until "timed out waiting for join" → tokio current_thread runtime is starving the mesh. The test annotation must be flavor = "multi_thread", worker_threads = 2 exactly as written in net.rs.

ERROR … Endpoint dropped without calling Endpoint::close on exit → benign teardown noise (see the round-trip test callout).

Browser build fails on tokio features → the wasm-incompatible tokio features must stay out of the base [dependencies] tokio entry. rt-multi-thread lives in the cfg(not(target_arch = "wasm32")) block.

🧪 The relay path (step 2)

The wasm build currently errors with relay support is not compiled into this build — that is the honest shipped state of relay.rs. To finish the hybrid: write a tiny tokio WebSocket listener on the host (say ws://0.0.0.0:9090), give each connected browser its own Packet reader/writer, broadcast browser bytes into the gossip topic, and forward NetEvents back out over the WebSocket. Every desktop-peer rule still applies (the host never joins, it answers). Build with dx build --web, serve the bundle, and browsers join like any other mesh node.

Step 13 / 14