ADCS.helpers.animations.godot.stream module¶
- class ADCS.helpers.animations.godot.stream.VizServer(host='127.0.0.1', port=0, token=None, mode='broadcast', queue_size=4096, ack_timeout=10.0)[source]¶
Bases:
objectTCP server the 3-D viewer connects to.
The Python side always listens and the viewer always connects, which works the same way for a viewer on the same machine and for a Windows viewer talking to a simulation inside WSL2.
A connecting viewer first sends
CONNECTwith the session token; a wrong token or protocol version gets anERRORand is disconnected. It then receivesHELLO(manifest and scene) followed by:playback (
serve_log()): the whole log asBLOCKmessages and anENDper run, thenENDfor the session. Every viewer that connects gets the full log.live (
begin_live()/publish_row()):ROWmessages as the simulation produces them.broadcast(default): rows go to a bounded queue drained by a background thread; if the viewer is slow or absent the oldest rows are dropped, so the simulation never waits. Rows produced before the viewer connects are kept up toqueue_size.lockstep: each row is sent synchronously and the simulation waits for the viewer’sACK(for deterministic capture). If the viewer disconnects or stops acknowledging, streaming stops with a warning and the simulation continues.
One live viewer is served at a time.
- Parameters:
host (str) – Interface to bind.
127.0.0.1keeps the stream local.port (int) – TCP port;
0picks a free one (seeaddress).token (str | None) – Session token the viewer must present; random if
None.mode (str) –
"broadcast"or"lockstep"(live sessions).queue_size (int) – Maximum rows buffered in broadcast mode.
ack_timeout (float) – Seconds to wait for an
ACKin lockstep mode.
- begin_live(manifest, scene)[source]¶
Start a live session. Rows are then sent with
publish_row().- Parameters:
manifest (Dict[str, Any]) – Manifest as built by
make_manifest().scene (Dict[str, Any]) – Scene description.
- Return type:
None
- close(flush_timeout=10.0)[source]¶
Send what is still queued (including a batch already being sent), then stop serving.
- Parameters:
flush_timeout (float) – Longest wait for a slow viewer [s]; what is not sent by then is dropped.
- Return type:
None
- publish_row(run_id, values)[source]¶
Send one row (all channels concatenated in manifest order).
Never raises because of the viewer: in broadcast mode a full queue drops its oldest row; in lockstep mode a lost viewer ends streaming.
- Parameters:
run_id (str)
values (ndarray)
- Return type:
None
- serve_log(log)[source]¶
Serve a recorded log to every viewer that connects (playback).
- Parameters:
log (VizLog)
- Return type:
None
- wait_for_client(timeout=None)[source]¶
Block until a viewer has connected (and received
HELLO).- Parameters:
timeout (float | None)
- Return type:
bool
- property connected: bool¶
- property dropped_rows: int¶
Rows discarded in broadcast mode because the queue was full.