3. Connect via WebSocket
With a ticket from the previous step, the game client opens a WebSocket connection directly to
the matchmaking gateway — using the wsEndpoint value from the ticket response, not a fixed URL.
<wsEndpoint>?ticket=<ticket>Every message on this connection is described in the AsyncAPI spec; see API Specs.
Always use the wsEndpoint from the ticket response
Because Pairiquium is globally hosted (see Generate a Ticket),
wsEndpoint points at whichever region this specific ticket was minted for — e.g.
wss://ws.eu-west-2.pairiquium.com or wss://ws.us-east-1.pairiquium.com. Don't hardcode a
region's URL in the client: a ticket is only valid against the region it names, so connecting
to the wrong one will be rejected even with an otherwise valid ticket.
Example
const socket = new WebSocket(
`${wsEndpoint}?ticket=${ticket}`
);
socket.addEventListener('open', () => {
// connected — see "Start a Search" for what to send next
});
socket.addEventListener('close', (event) => {
// if this fires immediately after opening, the ticket was rejected
// — see "Possible responses" below
});
socket.addEventListener('message', (event) => {
const action = JSON.parse(event.data);
// handle server-sent actions, e.g. MATCH_FOUND, ERROR
});What to expect
The ticket is checked as part of the connection handshake. There's no partial or pending state — the connection is either accepted, or the handshake is rejected and the socket never opens.
Possible responses
| Outcome | Meaning |
|---|---|
| Connection opens | The ticket was valid and unused. You can start sending actions — see Start a Search. |
| Connection rejected | The ticket is missing, malformed, expired, has already been used, or doesn't authorize this connection. |
On rejection, get a new ticket
Because tickets are single-use and short-lived, a rejected connection almost always means the ticket is no longer valid — not that something is wrong with your integration. Request a fresh ticket from your backend and try again rather than retrying the same one.
Connection lifetime
Once open, a connection stays alive for up to 2 hours. In practice, most connections end sooner — either the player finishes matchmaking, or the connection drops and is handled as described in Heartbeats & Disconnects.
Next
Once connected, players who want to queue with friends can first form a party; otherwise go straight to starting a search to queue the player for a match.