Understanding the Atmosphere Protocol - Atmosphere/atmosphere GitHub Wiki
Advanced topic. The protocol is handled transparently by
@ManagedServiceandatmosphere.js. This page documents the wire format for framework integrators or custom client implementations.
The Atmosphere Protocol is a lightweight handshake and message framing layer that works on top of any transport (WebSocket, SSE, long-polling, streaming).
When enableProtocol is true (default), the first message from the server contains metadata:
uuid|heartbeatInterval|heartbeatPaddingChar
Example:
a1b2c3d4-e5f6-7890-abcd-ef1234567890|30|X
The client stores the UUID and uses it for reconnection.
When trackMessageLength is true, messages are prefixed with their length:
<length>|<message>
Example:
42|{"author":"Alice","message":"Hello!","time":1708200000000}
This ensures complete message delivery over streaming and long-polling transports where message boundaries may not be preserved.
The server sends a single character (the heartbeatPaddingChar, default X) at regular intervals to keep connections alive across proxies and load balancers.
The client can also send heartbeats to the server, handled by the @Heartbeat annotation.
The client connects with its preferred transport. If it fails:
- Client tries
transport(e.g.,websocket) - If connection fails โ tries
fallbackTransport(e.g.,long-polling) - Notifies via
transportFailurehandler - On disconnect โ auto-reconnects with exponential backoff
disconnected โ connecting โ connected โ reconnecting โ connected
โ closed
โ error
Client Server
โ โ
โโโโโ GET /chat (upgrade) โโโโโโโ WebSocket handshake
โ โ
โโโโ uuid|30|X โโโโโโโโโโโโโโโโโ Protocol handshake
โ โ
โโโโ X โโโโโโโโโโโโโโโโโโโโโโโโโ Heartbeat
โ โ
โโโโโ {"author":"A","msg":"Hi"}โโ Client message
โ โ
โโโโ 35|{"author":"A","msg":"Hi"}โ Broadcast (with length prefix)
โ โ