JSON Protocol
The JSON protocol is the default hub protocol. Every message is a single JSON
object terminated by the ASCII record separator 0x1E.
Message types
type | Message | Direction |
|---|---|---|
| 1 | Invocation | both |
| 2 | StreamItem | both |
| 3 | Completion | both |
| 4 | StreamInvocation | both |
| 5 | CancelInvocation | both |
| 6 | Ping | both |
| 7 | Close | both |
| 8 | Ack | both (stateful reconnect) |
| 9 | Sequence | both (stateful reconnect) |
Frame shape
Each message is encoded as one JSON object followed by 0x1E:
{"type":1,"target":"Add","arguments":[40,2],"invocationId":"1"}\x1e
Selection
connection = HubConnection(protocol="json") # default
The handshake declares the protocol:
{"protocol": "json", "version": 2}\x1e
Version 2 is sent when stateful reconnect is negotiated; version 1 otherwise, so older servers keep working.
Example wire messages
Invocation:
{"type":1,"invocationId":"1","target":"Add","arguments":[40,2]}
StreamItem:
{"type":2,"invocationId":"1","item":0}
Completion with result:
{"type":3,"invocationId":"1","result":42}
Ack:
{"type":8,"sequenceId":7}
Sequence:
{"type":9,"sequenceId":8}
Parser behavior
- Unknown message types are ignored (forward compatibility).
- Missing required properties raise a
ProtocolError, which is fatal for the connection. - The
errorandresultproperties of aCompletionare mutually exclusive. 0x1E-delimited parsing is incremental and size-limited (maximum_receive_message_size, default 32 KiB).