Clipboard Sync

Copy on one device, paste on another. This Go example polls your clipboard every 500ms and relays any changes to a paired device over your self-hosted relay, end-to-end encrypted.

Prerequisites

  • A running Relayly server (e.g., docker compose up -d)
  • Go 1.24 or newer
  • macOS for full clipboard support (Linux/Windows receive a warning and no-op)

How it works

Each run registers itself via POST /api/v1/devices the first time (saving credentials to ~/.relayly/clipboard-device.json for later runs), then both devices connect to the same relay and pair using a 6-digit code. After pairing, each device watches its own clipboard. When the content changes, it sends the new text to the peer. When a message arrives from the peer, the local clipboard is updated.

Usage

Navigate to the example directory:

cd examples/go/clipboard-sync

Device A, start first, get a pairing code:

go run . --server ws://localhost:8080/ws

Output:

╔════════════════════════════════════╗
║  Pairing code:  483921              ║
╚════════════════════════════════════╝
Run on your other device:
  clipboard-sync --server ws://localhost:8080/ws --code 483921

Waiting for peer to connect…

Device B, paste the code:

go run . --server ws://localhost:8080/ws --code 483921

Once both sides connect:

Connected as device "a1b2c3d4-..."
Paired with 9e2c2132-...
Clipboard sync active. Press Ctrl+C to quit.

Now copy anything on either device. It will appear in the other device’s clipboard within 500ms.

Flags

FlagDefaultDescription
--serverws://localhost:8080/wsRelay server WebSocket URL
--code(empty)Pairing code from the other device. Omit to generate a new code.

Device identity

The first run registers a new device via POST /api/v1/devices and saves the returned device_id/device_token to ~/.relayly/clipboard-device.json, reusing them on later runs, the same load-or-create pattern every other official example uses.

The private key is stored at ~/.relayly/clipboard.key and reused across runs, giving each device a stable identity.

Platform notes

Clipboard access uses pbpaste / pbcopy on macOS. On other platforms the read always returns empty and writes print a warning. Pull requests adding Linux (xclip/wl-paste) or Windows support are welcome.

Check out the full source code at examples/go/clipboard-sync.