Files
2026-06-28 00:09:32 +02:00
..
2026-06-28 00:09:32 +02:00
2026-06-28 00:09:32 +02:00
2026-06-28 00:09:32 +02:00
2026-06-28 00:09:32 +02:00

simple-chat

This example implements a simple chat app inspired by p2pandaapp-cli-gomod. Peer discovery uses mDNS by default. It's also possible to connect to peers using direct peering or via a bootstrap node. An ephemeral topic stream is used for message exchange.

Static binary

You can build a statically linked binary with the following command. This means you can transfer and run the binary on a remote system for testing.

go build --ldflags '-linkmode external -extldflags=-static -s -w' ./simplechat.go

If you run into glibc incompatibility, you can compile with zig/musl.

CC="zig cc -target x86_64-linux-musl -lunwind" \
CGO_ENABLED=1 \
CGO_LDFLAGS="-static" \
GOOS=linux GOARCH=amd64 \
go build -v -a -ldflags '-extldflags "-static"' ./simplechat.go

Local network with mDNS

Terminal 1

simplechat

Terminal 2

simplechat

Peer to peer

Terminal 1

simplechat

Terminal 2

simplechat -peer <hex>

Peer via own bootstrap node

Terminal 1

simplechat -bootstrap

This will print the bootstrap node public key (i.e. <hex> in examples below).

Terminal 2

simplechat -peer <hex>

Terminal 3

simplechat -peer <hex>