Skip to content
  • Our Product
    • Namazu Elements
      • What is Elements?
      • Why open source?
      • Docs
        • Namazu Elements in Five Minutes or Less
        • RESTful APIs Library
        • Security Model
        • Accessing the Web UI (CMS)

    Our Product

    A logomark with three layered rhombuses adorning the lettermark that says Elements in bold all-caps sans-serif letters.
    • What is Namazu Elements? Discover our easy-to-use backend network solution built for online games. Rapidly enables full-scale multiplayer games or online solo adventures.
    • Why open source? Is there a truly open source server backend for connected games? There is now. Download and run a local copy of Namazu Elements and try it for yourself.
    Download Namazu Elements

    Get started

    • Quick start Read our Elements 5-minute quick start guide
    • Documentation Read our developer docs for learning more about Elements
    • RESTful APIs A full list of core API specs for working with the Elements framework
    • Security An overview of the server-authoritative security model of Elements
    • Accessing the CMS Manage your game with ease via the Namazu Elements CMS.

    Co-development Reimagined

    • Best real-time game backends in 2026 If you're researching an alternative to your current backend solution, we've prepared a report of all of the backend solutions on the market in 2026 and how Namazu Elements compares.
      Co-dev

    Recent Posts

    • The watercolor-styled Namazu Studios logo over a giant namazu lurking in the depth
      Namazu Studios Featured in San Diego Business Journal
      22 Sep 2025 Press
    • Namazu Elements 3.1 Released – Service Layer Fixes, Secure APIs, and Steam Bug Fix
      22 Apr 2025 Release Notes
  • Case Studies
  • About Us
  • News
  • Services
  • Book a call
namazu-studios-logo
Book a call
Popular Search Roblox

Getting Started

  • Namazu Elements in Five Minutes or Less
  • Overview
  • Accessing the Web UI (CMS)
  • CMS Feature Overview

Fundamentals

  • Why You Need a Server (and What “Authoritative” Means)
  • Elements as a Game Runtime
  • Where Your Authoritative Code Runs
  • Lifecycles and Flows

General Concepts

  • Custom Elements
  • Data Models
  • Security Model
  • N-Tier Architecture

Namazu Elements Core Features

  • Email Service
  • Applications
  • Sessions
  • Users and Profiles
  • Digital Goods
  • Progress and Missions
  • Progress and Missions (3.4+)
  • Leaderboards
  • Matchmaking – Comprehensive Guide
  • Friends
  • Followers
  • Product Bundles and SKUs
  • Item Ledger
  • Receipts
  • Reward Issuances
  • Save Data
  • Metadata
  • Metadata (3.4+)
  • Queries
  • User Authentication / Sign In
    • What is a User?
    • Email Verification
    • User Authentication in Elements
    • Account Linking
    • Setting Up Twitch OIDC Login (Backend)
    • OIDC Login for Thick Clients (Browser Redirect Flow)
    • Auth Schemes
      • Auth Schemes
      • OAuth2
      • OIDC
  • Features
    • Web3
      • Wallets
      • Vaults
      • Omni Chain Support
      • Smart Contracts
        • Smart Contracts
  • Queries
    • Advanced Operators
    • Object Graph Navigation
    • Boolean Queries
    • Base Query Syntax
  • Advanced Operators
    • .name
    • .ref

Your Game Code - Adding Custom Elements

  • Custom Code Overview
  • Windows Setup
  • Mac OS Setup
  • Ubuntu Linux Setup
  • Element Anatomy: A Technical Deep Dive
  • Introduction to Guice and Jakarta in Elements
  • Structuring your Element
  • Events
  • Packaging an Element with Maven
  • Deploying an Element
  • Preparing for code generation
  • Properties
  • Websockets
  • RESTful APIs
  • Direct MongoDB Access (3.5+)
  • Building the Example Element: A Complete Walkthrough
  • Building the Kotlin Example Element: A Complete Walkthrough

Configuration

  • Configuring External URLs for Deployment
  • Matchmaking – Comprehensive Guide
  • Direct Database Access and Batch Configuration
  • Connecting Namazu Elements to a TLS-Enabled MongoDB Replica Set
  • Batch Samples
    • Mission Upload Bash Script Sample
    • Item Upload Bash Script Sample

RESTful APIs

  • Importing into Postman
  • RESTful APIs Library
  • Swagger and Swagger UI

Add-Ons

  • Crossplay
    • Crossfire Client Libraries (JVM & Browser)
    • Crossfire Protocol Reference
    • Crossfire: Custom Matchmaking Algorithms
    • Namazu Crossfire (Multiplayer)
    • Deploying Namazu Crossfire in your game
  • Roblox
    • Roblox Overview
    • Secure Player Authentication & Registration
    • Global Matchmaking
    • Roblox Security Best Practices
  • Container on Demand
    • Namazu Conductor
    • Namazu Conductor Admin API
    • Configuring Namazu Conductor Providers
  • Commerce
    • Stripe
      • Stripe
      • Configuring the Stripe Element
      • Stripe REST API Reference
      • Stripe REST API Reference

Game Engine & Client Support

  • Unity
    • Elements Unity Plugin
    • Unity Crossfire Plugin
  • Gamemaker
    • Incorporating GMEXT-Elements into a GameMaker Project

Troubleshooting

  • Common Issues with Docker
  • Local SDK
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Could not load class : java.lang.NoClassDefFoundError
  • Namazu Elements Community Edition
    • Common Issues with Docker
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Running in the IDE
      • Exception in monitor thread while connecting to server localhost:27017
      • Could not deployAvailableApplications Jetty server Failed to bind to /0.0.0.0:8080 Address already in use

Releases

  • 3.8 Release Notes
  • 3.7 Release Notes
  • 3.6 Release Notes
  • 3.5 Release Notes
  • 3.4 Release Notes
  • 3.3 Release Notes
  • 3.2 Release Notes
  • 3.1 Release Notes
View Categories
  • Home
  • Docs
  • Add-Ons
  • Crossplay
  • Crossfire Protocol Reference

Crossfire Protocol Reference

Est. read time: 11 min read

AI Doc Summarizer Doc Summary
AI Doc Summarizer Thinking Thinking

This page documents the wire protocol used by Namazu Crossfire: the connection state machine, the JSON message envelope, the four handshake flows, the signaling model (direct vs. broadcast signals, backlog/replay, and signal lifecycles), control messages, error handling, and the ping/pong keepalive. It is intended for anyone implementing a Crossfire client from scratch, or extending the server with a custom matchmaking algorithm.

If you are integrating an existing client (Unity, JVM, or browser), see Crossfire Client Libraries instead — this page is for protocol implementers.


Connection lifecycle #

Every WebSocket connection to the Crossfire endpoint progresses through a single, one-way state machine:

WAITING → READY → HANDSHAKE → SIGNALING → TERMINATED

Crossfire connection state machine: WAITING to READY to HANDSHAKE to SIGNALING to TERMINATED, with error transitions to TERMINATED from READY and HANDSHAKE
  • WAITING — the socket has not yet been accepted by the server.
  • READY — the connection is open. The client must send a handshake message (FIND, JOIN, CREATE, or JOIN_CODE) as its first message. Any signaling or direct-signaling messages sent this early are buffered rather than rejected, and are replayed once the connection reaches SIGNALING.
  • HANDSHAKE — entered as soon as a handshake message is accepted. A second handshake attempt is not allowed; the connection may only enter this phase once. Signaling messages received while still in this phase are also buffered.
  • SIGNALING — entered once authentication succeeds and a match has been assigned. From here the client exchanges signals and control messages until the socket closes.
  • TERMINATED — absorbing. Once terminated, further inbound messages are logged and dropped rather than causing further errors.

Any message whose category is not valid for the current phase closes the connection with a policy-violation close code and a ProtocolStateException.

Message envelope and wire format #

Every message is a single JSON object with a type discriminator field. The server resolves type against ProtocolMessageType and deserializes the REST of the object into the matching Java class. There is no separate envelope wrapper — the payload fields sit alongside type at the top level. Unknown fields are ignored (the shared Jackson mapper has FAIL_ON_UNKNOWN_PROPERTIES disabled), which keeps the wire format forwards-compatible across minor versions.

{
  "type": "STRING_BROADCAST",
  "profileId": "abc123",
  "lifecycle": "Session",
  "payload": "hello"
}

Binary payloads (BINARY_BROADCAST, BINARY_RELAY) are base64-encoded strings on the wire, per standard Jackson byte[] handling.

Each ProtocolMessageType belongs to exactly one category (ProtocolMessageCategory), and the connection phase determines which categories are legal to receive:

CategoryUsed forValid phase
HANDSHAKEFIND, JOIN, CREATE, JOIN_CODE, CREATED, MATCHEDREADY
SIGNALINGBroadcast signals delivered to every other participantSIGNALING
SIGNALING_DIRECTSignals addressed to one specific recipient (SDP/ICE exchange, relays)SIGNALING
CONTROLOPEN, CLOSE, END, LEAVESIGNALING
ERRORERROR (server → client only)any phase

Some message types are server-only (ProtocolMessage.isServerOnly() returns true) — for example MATCHED and all server-driven presence signals (CONNECT, DISCONNECT, HOST, SIGNAL_JOIN, SIGNAL_LEAVE). If a client sends one of these, the server rejects it with an INVALID_MESSAGE error and closes the connection.

Protocol versions #

Crossfire currently defines two protocol versions, negotiated per-connection by the version field of the handshake request:

  • V_1_0 — the original handshake flows: FIND (matchmaking queue) and JOIN (join/resume by match id). All signaling, control, and error message types are also V_1_0.
  • V_1_1 — adds the create/join-code flow: CREATE and JOIN_CODE, plus the CREATED response.

A version is compatible with a request if the major versions match and the server/Session version’s minor is greater than or equal to the requested minor (Version.isCompatibleWithRequestedVersion). The server routes each handshake request to a dedicated handler based on the version: V10HandshakeHandler only understands FIND/JOIN, while V11HandshakeHandler only understands CREATE/JOIN_CODE. Both extend the shared V1HandshakeHandler base, which manages authentication and the handshake-internal state machine (READY → AUTHENTICATING → AUTHENTICATED → MATCHING → TERMINATED) common to all four flows.

The four handshake flows #

Every flow follows the same shape: client sends a handshake request → server authenticates the Session/Profile → server resolves a MatchmakingAlgorithm (default, or named via the Application’s MatchmakingApplicationConfiguration.matchmaker) → the algorithm asynchronously matches or creates → server sends a handshake response → connection transitions to SIGNALING.

Sequence diagrams for the four Crossfire handshake flows: FIND, JOIN, CREATE, and JOIN_CODE

FIND (v1.0) — join the matchmaking queue #

Request (FindHandshakeRequest): type: "FIND", version, sessionKey (required), profileId (optional — falls back to the Profile attached to the Session), configuration (required — the name of the MatchmakingApplicationConfiguration to use).

The server resolves the named FindMatchmakingAlgorithm and calls initialize(request), which is expected to find-or-create a MultiMatch and add the Profile to it. Response: MatchedResponse (type: "MATCHED", matchId, profileId).

JOIN (v1.0) — rejoin a known match #

Request (JoinHandshakeRequest): type: "JOIN", version, sessionKey, matchId (required), profileId (optional). Used to reconnect after a disconnection or network interruption — the client already knows its match id.

The server looks up the match’s own MatchmakingApplicationConfiguration (so the join uses the same algorithm the match was created under), then calls the algorithm’s resume(request), which verifies the requesting Profile is actually a member of the match before returning a handle. Response: MatchedResponse.

CREATE (v1.1) — create a joinable match #

Request (CreateHandshakeRequest): type: "CREATE", version (defaults to V_1_1), sessionKey, profileId, configuration (required).

Resolves a JoinCodeMatchmakingAlgorithm and calls initialize(request), which creates the match and generates a join code. Response: CreatedHandshakeResponse (type: "CREATED", matchId, joinCode, profileId) — the join code is the piece of data a game would show the host to share with other players.

JOIN_CODE (v1.1) — join by code #

Request (JoinCodeHandshakeRequest): type: "JOIN_CODE", version, sessionKey, joinCode (required), profileId.

The server looks the match up by join code, resolves the same JoinCodeMatchmakingAlgorithm the match was created with, and calls resume(request), which adds the joining Profile to the match if it isn’t already a member. Response: MatchedResponse (not CreatedHandshakeResponse — only the creator receives the join code back; subsequent joiners already know it).

All four flows are pluggable — see Custom Matchmaking Algorithms for how to replace the default FIFO/join-code implementations with your own matching, rating, or lobby logic.

Signaling phase #

Once a connection enters SIGNALING, the server sends the handshake response and then joins the connection to the match’s in-memory mailbox. From this point, three kinds of traffic flow over the socket: broadcast signals, direct signals, and control messages.

Broadcast vs. direct signals #

A broadcast signal (BroadcastSignal) is delivered to every other participant in the match except the sender. Client-originated broadcast types are STRING_BROADCAST and BINARY_BROADCAST (arbitrary game data). Server-originated (“server-only”) broadcast types report match presence: CONNECT, DISCONNECT, HOST, SIGNAL_JOIN, SIGNAL_LEAVE.

A direct signal (DirectSignal) is addressed to exactly one recipient Profile via recipientProfileId, and it is a protocol error (UnexpectedMessageException) to address one to yourself. This is the category used for WebRTC negotiation: SDP_OFFER, SDP_ANSWER, and CANDIDATE (ICE candidates, carrying mid/midIndex/candidate). It’s also used for point-to-point Application data that shouldn’t go to the whole match: STRING_RELAY, BINARY_RELAY.

The server validates both sender and recipient (for direct signals) are actual members of the match before delivering; an unknown Profile id results in a ForbiddenException.

Signal lifecycle: ONCE, Session, MATCH #

Every signal declares a SignalLifecycle that controls whether — and for how long — the server buffers it for replay to clients that connect or reconnect later:

  • ONCE — fire-and-forget. Delivered only to currently-connected recipients; never buffered. If nobody is listening at the moment it’s sent, it’s lost. Default lifecycle for STRING_BROADCAST, BINARY_BROADCAST, STRING_RELAY, BINARY_RELAY, and the server’s DISCONNECT signal (a disconnect notice from five minutes ago isn’t useful to a new joiner).
  • Session — buffered for the lifetime of the sender’s current connection; cleared as soon as that connection’s subscription disconnects. Used for CONNECT, HOST, and the WebRTC negotiation signals SDP_OFFER/SDP_ANSWER/CANDIDATE — if a peer drops mid-negotiation, that negotiation state should not survive to a fresh connection; the spec notes a dropped peer should force a fresh SDP offer rather than replay the stale one.
  • MATCH — buffered for the entire life of the match, replayed to every new joiner regardless of when they connect. Used for SIGNAL_JOIN/SIGNAL_LEAVE (so a late joiner sees the full roster history) and available as an option on StringBroadcastSignal/BinaryBroadcastSignal/StringRelayDirectSignal/BinaryRelayDirectSignal for game data a late joiner needs (e.g. authoritative game state snapshots).

When implementing a new signal type of your own (via a custom control flow or algorithm), choose MATCH if late-joining players need the information and Session if it’s transient per-connection state; reach for ONCE only for data with no replay value.

Backlog and replay for late joiners #

Each match keeps one bounded outbox per Profile, split into a match list (holds MATCH-lifecycle signals) and a Session list (holds Session-lifecycle signals). Outboxes are bounded (elements.crossfire.match.signaling.max.backlog.size, default 256 entries total across the match) — exceeding it raises a MessageBufferOverrunException and terminates the connection, so don’t lean on MATCH-lifecycle broadcasts as an unbounded event log.

When a Profile first joins a match, the server synthesizes and buffers a SIGNAL_JOIN for it. When a connection attaches (connect()), the server synthesizes and buffers a CONNECT signal, assigns that Profile as host if no host currently exists (broadcasting HOST), and then replays every signal across every Profile’s outbox that isFor() the connecting Profile — this is how a client that reconnects mid-match catches up on roster state and any in-flight game state without having missed it. If a second connection attempt comes in for a Profile that’s already connected, the existing subscription is force-disconnected with a DuplicateConnectionException before the new one takes over, guaranteeing at most one live connection per Profile per match.

If the host’s connection disconnects cleanly, the server automatically reassigns host to another currently-connected participant and re-broadcasts HOST. If every participant disconnects (but the match record itself isn’t ended), or every participant formally leaves the match, the server ends and removes the match automatically.

Sequence diagram showing a late-joining profile receiving replayed backlog signals from the match mailbox

Control messages #

Control messages manage the match itself rather than carrying game data. All are client-originated (there is no server-originated control message):

TypeHost-only?EffectConnection result
OPENYesRe-opens the match to new participantsconnection stays open
CLOSEYesCloses the match to new participants (existing participants unaffected)connection stays open
ENDYesEnds the match entirelyconnection stays open
LEAVENoRemoves the sending Profile from the match (and deletes the match if it was the last Profile)connection is closed by the server

“Host-only” messages are not currently rejected server-side based on sender identity in the base control Service — enforcing that only the host Profile may send OPEN/CLOSE/END is the responsibility of a ControlService implementation if you replace the default, or of the game client’s own UI logic.

Error handling #

Protocol-level errors are delivered as a single ERROR message (StandardProtocolError: code + human-readable message) immediately before the server closes the WebSocket. There is no error recovery within a connection — every error is terminal for that socket; the client must reconnect (typically via JOIN or JOIN_CODE) to resume.

Built-in error codes (ProtocolError.Code): UNKNOWN, TIMEOUT, INVALID_MESSAGE. Domain exceptions from the wider Elements SDK (BaseException subclasses — e.g. ForbiddenException, MultiMatchNotFoundException) are mapped through their own getCode() value instead. The WebSocket close code sent alongside the error depends on the exception type:

  • TimeoutException → GOING_AWAY
  • ProtocolStateException, UnexpectedMessageException, MessageBufferOverrunException → VIOLATED_POLICY
  • Other BaseExceptions → TRY_AGAIN_LATER for an OVERLOAD code, VIOLATED_POLICY otherwise
  • Anything else → UNEXPECTED_CONDITION

Ping/pong keepalive #

The server drives keepalive, not the client. On connection start it sets the WebSocket Session’s max idle timeout and schedules a native WebSocket ping on a fixed delay:

  • dev.getelements.elements.ping.interval.seconds — how often the server pings (default 30s).
  • dev.getelements.elements.timeout.seconds — the Session’s max idle timeout (default 90s); if no traffic (including pong replies) is seen within this window, the container closes the socket.

A pong reply resets container-level idle tracking automatically; the server does not otherwise track missed pongs itself. If sending a ping fails outright (e.g. the socket is already broken), the server proactively closes the Session with an UNEXPECTED_CONDITION close code rather than waiting for the idle timeout.

Implementation notes #

The project’s internal engineering notes flag a historical race condition in the handshake shutdown path — using updateAndGet where getAndUpdate was needed, which could miss cancelling in-flight matchmaking work. As of this writing, V1HandshakeHandler.stop() correctly uses getAndUpdate(V1HandshakeStateRecord::terminate) and inspects the previous phase to decide whether to cancel a still-MATCHING handle, so this particular path is implemented correctly. If you’re implementing your own MatchHandle subclass, AbstractMatchHandle.leaveMatch() (in the util module) is the canonical example of this pattern: it uses getAndUpdate specifically so it can act on the match’s state before the termination transition overwrote it.

What are your Feelings
Still stuck? How can we help?

How can we help?

Updated on August 14, 2026
Crossfire Client Libraries (JVM & Browser)Crossfire: Custom Matchmaking Algorithms
Table of Contents
  • Connection lifecycle
  • Message envelope and wire format
  • Protocol versions
  • The four handshake flows
    • FIND (v1.0) — join the matchmaking queue
    • JOIN (v1.0) — rejoin a known match
    • CREATE (v1.1) — create a joinable match
    • JOIN_CODE (v1.1) — join by code
  • Signaling phase
    • Broadcast vs. direct signals
    • Signal lifecycle: ONCE, SESSION, MATCH
    • Backlog and replay for late joiners
  • Control messages
  • Error handling
  • Ping/pong keepalive
  • Implementation notes
  • Documentation
  • Terms of Service
  • Privacy Policy
  • Contact us
  • Linkedin
  • Join our Discord

Namazu Studios LLC is powered by Namazu Elements, an open source modular backend framework for connected games.

Namazu Elements
  • Download
  • About Elements
  • Open source
  • Documentation
  • Support
Namazu Studios
  • Case Studies
  • About Us
  • News
Best realtime game backends 2026
Get in Touch
  • info@namazustudios.com
  • Book a call
  • (619) 862-2890
  • Linkedin
  • Discord

©2008-2026 Namazu Studios. All Rights Reserved.