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
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 Output:
╔════════════════════════════════════╗
║ Pairing code: 483921 ║
╚════════════════════════════════════╝
Run on your other device:
clipboard-sync --server ws://localhost:8080 --code 483921
Waiting for peer to connect… Device B — paste the code:
go run . --server=ws://localhost:8080 --code 483921 Once both sides connect:
Connected as device "clipboard-xxxxxxxxxxxx"
Paired with clipboard-yyyyyyyyyyyy
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
| Flag | Default | Description |
|---|---|---|
--server | ws://localhost:8080 | Relay server WebSocket URL |
--code | (empty) | Pairing code from the other device. Omit to generate a new code. |
Device identity
The device ID is derived from the first 16 characters of the public key, prefixed with clipboard-. You can override it by setting the RELAYLY_DEVICE_ID environment variable:
RELAYLY_DEVICE_ID=my-macbook go run . --server=ws://localhost:8080 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.