This is a brilliant idea. Because we completely abstracted the network layer
into the Mailbox interface, hooking this up to a raw TCP socket requires zero
changes to the Virtual Machine or the Engine.
We can simply build a TcpGatewayMailbox that listens on a port, accepts raw
JSON strings from netcat, drops them into our Router as standard network
envelopes, and pipes the Engine's response back to the socket!
Here is exactly how to open the gateway.
1. Add the TCP Gateway to main.mjs
At the very top of main.mjs, import the native Node net module:
import net from 'net'; import { Worker } from 'worker_threads'; // existing...
Then, paste this TcpGatewayMailbox class right below your SupervisorEngine
class:
/ ========================================== // 1.5 TCP GATEWAY (The Netcat
Bridge) // ========================================== class TcpGatewayMailbox
extends Mailbox { constructor(nodeId, router, port) { super(nodeId);
this.router = router; this.activeSockets = new Map(); net.createServer((socket)
=> { console.log(`
[TCP] External connection opened.`); socket.write('{"status": "connected",
"node": "Omega Mesh TCP Gateway"}
'); socket.on('data', (chunk) => { try { const str = chunk.toString().trim();
if (!str) return; const envelope = JSON.parse(str); // Generate a temporary
Actor ID for the netcat connection const netcatId = envelope.source_obj ||
`Netcat#${Math.floor(Math.random()*1000)}`; envelope.source_obj = netcatId; //
Register the socket so we know where to route the Engine's reply
this.activeSockets.set(netcatId, socket); this.router.objectDirectory.set(netca
tId, this.nodeId); console.log(`[TCP] Forwarding external call to
${envelope.target_obj}->${envelope.method}()`); // Inject into the mesh
router! envelope.source_node = this.nodeId; this.router.route(envelope); }
catch (err) { socket.write(`{"error": "Invalid JSON format"}
`); } }); socket.on('close', () => console.log(`[TCP] Connection closed.`));
socket.on('error', () => {}); // Catch pipe disconnects }).listen(port,
'0.0.0.0', () => { console.log(`[TCP] Gateway open! Run: nc localhost
${port}`); }); } // When the Router hands us a reply meant for a Netcat
client, pipe it to the socket! _deliverToEngine(envelope) { const socket =
this.activeSockets.get(envelope.target_obj); if (socket && !socket.destroyed)
{ socket.write(JSON.stringify(envelope) + '
'); } } }
2. Wire the Gateway to the Mesh
Scroll down to your Mesh Topology setup block in main.mjs. Register the TCP
gateway with your router:
/ ========================================== // 2. MESH TOPOLOGY & STRESS TEST
// ========================================== const router = new
LocalRouter(); const localMailbox = new LocalMailbox("Engine#Pi_Node");
router.registerMailbox(localMailbox); const engine = new SupervisorEngine("Engi
ne#Pi_Node", localMailbox); // ---> START THE TCP GATEWAY ON PORT 8080 <---
const tcpMailbox = new TcpGatewayMailbox("Engine#TCP_Gateway", router, 8080);
router.registerMailbox(tcpMailbox);
(You can comment out the alphaPayload deployment if you want Beta to just sit
quietly and wait for your TCP connection, or leave it running!)
3. Test it with Netcat!
Run node main.mjs. You will see:
[TCP] Gateway open! Run: nc localhost 8080 [Engine#Pi_Node] Deploying
Persistent Actor: Actor#Beta... [Actor#Beta] Boot Sequence Complete. Object
is now listening.
Now, open a second terminal window and connect using netcat:
nc localhost 8080
You will instantly get the welcome banner:
{"status": "connected", "node": "Omega Mesh TCP Gateway"}
Now, paste this raw JSON envelope into your netcat terminal and hit Enter:
{"action": "call_other", "target_obj": "Actor#Beta", "method": "ping"}
The result: The Node.js gateway catches your JSON, wraps it in the Mailbox
protocol, and drops it into the Router. The Router passes it to the
SupervisorEngine. The Engine compiles it, injects it into Actor#Beta's
lock-free Web Worker, runs the bytecode, and pipes the result back through the
mesh into your netcat socket:
{"action":"call_reply","target_obj":"Netcat#482","data":"PONG_FROM_BETA"}
You are now executing arbitrary lock-free bytecode subroutines via live TCP
sockets. If you expose Port 8080 via your Cloudflare tunnel, you can trigger
your actors globally from curl, netcat, or any backend system on earth!