WIRE LAB · ENCODE · PARSE · INSPECT
Server-sent events: bytes, fields and dispatch
Edit an event stream and inspect how UTF-8 chunks, blank lines and event IDs change what the client receives.
Delivered application output
Exact byte and parser state
Chunks are not events
This experiment encodes the editable stream as UTF-8 bytes and feeds them to an incremental parser. A transport chunk can end halfway through an emoji, field or line. The decoder retains incomplete UTF-8 input; the line parser accumulates fields; a blank line dispatches an event only when a data field has contributed content. Received events are retained in the output, rather than disappearing when an animated marker leaves the screen. The byte grid shows exact received hexadecimal values, and the inspector exposes the pending line, data buffer and event-ID state.
Change the stream deliberately
Event stream text is limited to two thousand characters. Lines beginning with a colon are comments. A data field appends its value and a newline; consecutive data fields become one event’s data separated by newlines. An event field chooses the event type, otherwise message is used. An id field changes the ID buffer, including clearing it when empty; an ID containing a null character is ignored. A valid decimal retry field sets the parser’s reconnection delay value. This bounded parser ignores values outside JavaScript’s safe integer range. Chunk bytes controls delivery granularity. Line endings selects LF, CRLF or CR after normalizing the editor’s line breaks. Remove final line ending demonstrates a truncated final event.
Inspect a real dispatch boundary
Restore defaults and choose one-byte chunks. Step through the stream to see that the emoji is not exposed as broken text and no event appears before its blank-line delimiter. At the end, the first event has type update, data containing Hello followed by a newline and world with an emoji, and ID seven. The second event has ID eight. Enable removal of the final line ending: the first event still dispatches, but the second remains pending. Edit the stream to use an empty id field followed by data and a blank line; the reconnect-header display becomes omitted. Repeating an ID does not automatically deduplicate events in this parser.
Use playback as inspection, not a network claim
Play reveals the bounded byte sequence over sixty inspection seconds. Pause holds it; Next chunk advances one recorded parser step; Restart rewinds; Speed changes viewing pace; Inspect time scrubs the same bytes. Restore defaults resets the editor and controls. Editing an input recomputes the fixture and pauses at the beginning. The output is displayed as literal text, never interpreted as HTML. Reconnect header shows what the last dispatched ID would imply; no reconnection, server-side replay store or delivery guarantee is implemented. End of stream flushes UTF-8 decoding but does not dispatch an unfinished event. HTTP status handling, MIME checks, CORS, credentials, proxy buffering and real EventSource lifecycle behavior are outside this teaching parser.