magic number
A fixed value, placed at the start of a file or message or built into a protocol, that lets a reader recognise the format.
In more detail
A parser checks it first and rejects data that does not start with it. The WebSocket handshake uses a fixed magic string when computing its accept header.
Related terms
- binary protocol — A network or file format that encodes messages as raw bytes at fixed positions instead of readable text.
- Sec-WebSocket-Key and Sec-WebSocket-Accept — The WebSocket handshake headers: the client sends a random key, and the server proves it understood by returning a SHA-1 hash of that key joined to a fixed magic string.
Taught in
- Binary Data Manipulation: TypedArrays & Endianness — Node.js Internals & Backend Services
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services