proj# Plan: Stream Doom → Node.js Server → Browser
The full pipeline already exists in code:
src/i/StdoutFrameWriter.java— writes binary RGBA frames to stdoutserver/server.js— Node.js server parses frames, converts to JPEG, broadcasts via WebSocketserver/index.html— browser client renders JPEG frames on a canvas
The recent commits ("still trying to output over stream") indicate the stream is not working. The root cause is a stdout redirect bug explained below.
In Engine.main() (line 55), when -stdout is detected:
System.setOut(System.err); // redirect ALL Java output to stderrThis runs before new Engine(argv) — and therefore before new StdoutFrameWriter().
In StdoutFrameWriter constructor (line 44):
this.out = new DataOutputStream(new BufferedOutputStream(System.out, 256 * 1024));At this point System.out is already the redirected stream (i.e. stderr). So frame data is written to stderr, not stdout. The Node.js process piping stdout receives nothing.
Replace the constructor body with:
import java.io.FileDescriptor;
import java.io.FileOutputStream;
public StdoutFrameWriter() {
// FileDescriptor.out is the real file descriptor 1 (stdout), unaffected
// by System.setOut() which only redirects the Java PrintStream wrapper.
this.out = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(FileDescriptor.out), 256 * 1024)
);
}This bypasses System.setOut() entirely and writes directly to the OS-level stdout fd, which is what the Node.js pipe reads.
The current GAME_ARGS (line 40) lacks -nosound and a game-activity mode. Update:
const GAME_ARGS = [
'-jar', 'src/mochadoom.jar',
'-stdout',
'-nosound',
'-demokeys', // drive game with synthetic keys so frames aren't static
];Alternatively use -timedemo demo1 instead of -demokeys to replay a built-in demo.
Ignore the demo all togerther
| File | Change |
|---|---|
src/i/StdoutFrameWriter.java |
Constructor: new FileOutputStream(FileDescriptor.out) instead of System.out |
server/server.js |
Add -nosound and -demokeys to GAME_ARGS array |
# 1. Install Node deps (once)
cd server; npm install; cd ..
# 2. Build the JAR
.\build-jar.ps1
# 3. Start the streaming server (spawns Java automatically)
cd server; node server.js --spawnThen open http://localhost:8080 in a browser. The canvas should show live Doom frames.
- Terminal shows:
DOOM stream server running at http://localhost:8080 - Browser status pill shows LIVE (green dot)
- Frame counter increments in the top-right stats
- FPS meter shows a positive value
- Canvas displays Doom gameplay frames