Python UDP example
examples/python/ is a standalone host for the Python bindings. It uses a
one-way UDP link: the sender owns
the socket, while predsync owns frame bytes and receiver-side trust.
Build the extension and run the deterministic path from the repository root:
pixi run python-build
python examples/python/telemetry_udp.py self-test
self-test uses an in-memory link that drops every eighth frame. It verifies
that a sequence gap marks predictor fields Unknown, and that later delivered
values plus staggered periodic Reset frames restore usable values. No network
access is required.
Sender and receiver
For a real loopback, start the receiver first:
python examples/python/telemetry_udp.py receive 127.0.0.1:9000 1000
python examples/python/telemetry_udp.py send 127.0.0.1:9000 1000
The sender creates one Encoder and sends one frame per datagram. The receiver
keeps a separate Decoder for each source address, because the message ID
selects a message type rather than a sender:
decoder = decoders.setdefault(
peer,
predsync.Decoder(
Telemetry.schema_yaml,
message=Telemetry.message_index,
resync_n=1,
),
)
decoded = decoder.feed(frame)
Each datagram is exactly one predsync frame, so no extra framing is needed.
Check decoded.fields before trusting predicted values; decoded.missed and
decoded.resynced report loss and recovery.
Ctrl-C statistics
Press Ctrl-C in the sender (or let the frame count complete) to print mean, median and a 95% confidence interval for three numbers:
- fields predicted per frame, from
info["n_predicted"]; - byte savings per frame relative to a fresh encoder carrying the same sample and tick, i.e. the cost of sending every true value every time;
- the same saving as a percentage of the baseline frame size.
A line with maximum and mean message size precedes an overall percentage reduction across all encoded frames. The interval is a seeded bootstrap percentile interval of the mean, so the output is reproducible. It describes the frames the sender encoded; predsync has no back channel, so the sender cannot know which frames the receiver saw.