> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pxxl.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Persistent connections

> Keep WebSockets open around the clock, through deploys and platform updates, on a dedicated WebSocket edge in Europe or Lagos.

Persistent connections move a project's WebSocket traffic onto a dedicated WebSocket edge built to hold connections for days. Connections stay open through your deploys and through Pxxl's own updates, so devices don't all reconnect at once.

Use it for EV chargers, IoT devices, trackers, live feeds, trading screens, multiplayer and anything that must stay connected. A chat or live-update feature in a normal web app doesn't need it: plain [WebSockets](https://docs.pxxl.app/networking/edge-settings.md#websockets) are enough when a reconnect every few hours is fine.

| | |
| - | - |
| **Plans** | Pro and Enterprise |
| **Included** | Pro: 2,000 open connections per project. Enterprise: 20,000. |
| **More connections** | \$3 a month per extra 5,000 |
| **Edges** | **Europe** (France) and **Lagos** (Nigeria) |
| **Domains** | Custom domains you choose. Pxxl addresses aren't used. |
| **Projects** | Web services, Dockerfile and image projects. Static sites have no server to keep a connection open. |

## Choose an edge

Pick the edge closest to your devices. A connection is held at the edge, so a nearby edge means lower latency and fewer dropped connections on mobile networks.

| Edge | Location | Use it for |
| - | - | - |
| **Europe** | France | Devices in Europe. The default. |
| **Lagos** | Lagos, Nigeria | Devices in Nigeria and West Africa. |

Each domain has its own edge, so one project can serve European devices on `ws.example.com` from Europe and Nigerian ones on `ng.example.com` from Lagos.

## Turn it on

**1. Open Persistent connections**

Open the project, then **Networking > Persistent connections > Settings**.

**2. Switch it on**

Turn on **Persistent connections**. This also turns on WebSockets for the project.

**3. Add a domain**

Add the custom domain your devices connect to, such as `ws.example.com`. You can pick a domain the project already has, add a new one, or type a subdomain of a domain you bought on Pxxl.

**4. Pick its edge**

Choose **Europe** or **Lagos**, review, and save.

**5. Set DNS if asked**

Depending on where the domain's DNS is, Pxxl either updates it for you or shows one record to set. See below.

The domain shows **Waiting for DNS** until the record is right, usually a few minutes, then **Connected**.

## DNS for each kind of domain

| Your domain | What you do |
| - | - |
| On **Pxxl DNS** (bought on Pxxl) | Nothing. Pxxl points the record at the edge for you. |
| **Points at a Pxxl alias** (a `CNAME` to `<id>.dns.pxxl.app`) | Nothing. Your `CNAME` stays; Pxxl moves the alias to the edge. |
| **DNS at your provider** with any other record | Change the record to the one shown, below. |

For a domain at your own DNS provider, set:

| Name | Type | Value |
| - | - | - |
| Subdomain, such as `ws` | `CNAME` | The edge's hostname shown in the dashboard |
| Root domain `@` | `A` | The edge's IP shown in the dashboard |

Connections stay on the old edge until DNS points at the new one, so the switch is gradual and safe.

> [!WARNING]
>
> If your DNS provider can proxy the record (Cloudflare's orange cloud), set it to **DNS only**. Proxied connections are cut after about 100 seconds without traffic.

## Connect from a device

Nothing changes in your app. Keep serving WebSockets on its port, and connect to the domain over `wss://`:

```js theme={null}
const socket = new WebSocket("wss://ws.example.com/socket");

socket.addEventListener("open", () => socket.send(JSON.stringify({ type: "hello", deviceId })));
socket.addEventListener("close", () => setTimeout(connect, 1000 + Math.random() * 4000));
```

Still reconnect with a random delay when a connection closes: networks drop connections, and a random delay stops thousands of devices reconnecting in the same second.

Send a small ping every 30 to 60 seconds from the device or the server, so mobile carriers and home routers don't close an idle connection.

## Usage and history

| Page | What it shows |
| - | - |
| **Usage** | Open connections against your allowance, the peak this month, and data received and sent. |
| **Connection history** | When connections opened and closed, how long each stayed open, and why it closed (the WebSocket close code), with the domain and the client's country and network. |

Pxxl emails you when open connections reach 80% and 100% of your allowance. Past the allowance plus 10%, new connections are refused until some close or you add more.

## Turn it off

Turn off **Persistent connections** and the chosen domains go back to the standard edge. WebSockets keep working there, but connections close on deploys and platform updates.

## Where to go next

> [card] [Project networking](https://docs.pxxl.app/networking/edge-settings.md)
>
> WebSockets, security and access rules.

> [card] [Connect a domain](https://docs.pxxl.app/domains/connect.md)
>
> Add the domain your devices use.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.