THE RELAY

What lets two players reach each other across the internet. One Python file, standard library only, run on a machine of your own.

1Why it exists

Two home routers accept no incoming connections, so neither phone can host for the other. Instead both dial out to a relay, which pairs them by a short code and then pipes bytes between them. It understands nothing about the game: once two players are paired, every line one sends is handed to the other untouched.

There is no relay run by the developer. If you want to play across the internet, you or someone you trust runs this. On the same Wi-Fi, or over Bluetooth with Nearby, no relay is needed at all.

2The files

relay.py

The relay itself. Python 3.8 or newer, no dependencies.

test_relay.py

Drives it over real sockets, the way two players would.

battleship-relay.service

systemd unit: unprivileged account, no filesystem, restart on failure.

install-relay.sh

Installs that unit on a Debian or Ubuntu host. Run once, as root.

LICENSE

MIT. Keep the notice with any copy you pass on.

3Running it

On anything with Python 3.8 or newer — a spare machine, a Raspberry Pi, or the cheapest VPS going:

python relay.py                                  # 0.0.0.0:8642, open to anyone
python relay.py --port 9000 --host 127.0.0.1
python relay.py --key-file /etc/sea-duel-relay/key
python relay.py --tls-cert fullchain.pem --tls-key privkey.pem

Then both players type the address into Two devices › Online in the app. One taps Create a game and reads out the code it is given; the other types it in.

4On a public address

Without a key, anyone who finds the port can open rooms on it. --key-file makes the relay serve only players who know the key in that file, which both of them enter under Access key. The key is compared in constant time, and a wrong one costs a second before the connection is dropped, so guessing it over the network gets nowhere.

--tls-cert and --tls-key take an ordinary certificate — a certbot one does nicely — and players switch on Encrypted connection. Without it the relay can read the shots passing through, which matters if it is not yours.

For a permanent install, install-relay.sh sets up the systemd unit, an unprivileged account and the key file in one go.

5Licence

MIT, the same as the game it belongs to. Copyright © 2017 Danny Burt for the original work and © 2026 Andreas Grauf for this. The full text is in LICENSE, and it needs to travel with any copy you pass on.