Skip to content

Navigation Menu

Sign in
Sign up

Understanding the Atmosphere Protocol

jfarcand edited this page Feb 18, 2026 · 13 revisions

Understanding the Atmosphere Protocol

Advanced topic. The protocol is handled transparently by @ManagedService and atmosphere.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).

Handshake

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.

Message Framing (TrackMessageSize)

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.

Heartbeat

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.

Transport Negotiation

The client connects with its preferred transport. If it fails:

  1. Client tries transport (e.g., websocket)
  2. If connection fails → tries fallbackTransport (e.g., long-polling)
  3. Notifies via transportFailure handler
  4. On disconnect → auto-reconnects with exponential backoff

Connection States

disconnected → connecting → connected → reconnecting → connected
 ↘ closed
 ↘ error

Client-Server Message Flow

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)
 │ │

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /