Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Project516/p2p-chat/llms.txt

Use this file to discover all available pages before exploring further.

To start a chat, one participant must listen for an incoming connection. The listener binds to a TCP port and waits; the other participant then connects to that address. This page covers everything you need to get a listener running.

Starting the listener

1

Choose an address

Pick a host and port for your listener. The format is host:port, for example localhost:5555 for local testing or 0.0.0.0:5555 to accept connections from any network interface.
Use 0.0.0.0 as the host when you want to accept connections from another machine on your network or over the internet.
2

Run the listen command

go run . listen <address>
For example, to listen on port 5555 locally:
go run . listen localhost:5555
Or use the convenience script included in the repository:
./host.sh
The script runs go run . listen localhost:5555 for you.
3

Wait for your peer

After the command runs, you will see:
Listening on localhost:5555
The process blocks here until a peer connects. Once they do:
Connected
Encryption established.
You are now in an active chat session.

Always provide an address

Do not run go run . listen without an address argument. The source code prints an error and a default address message, but then immediately tries to read the missing argument, which causes a runtime panic:
Error: No port given
Defaulting to port :5555
panic: runtime error: index out of range
Always pass the address explicitly: go run . listen localhost:5555.

Firewall and network considerations

When both participants are on the same machine, localhost works without any additional setup. For cross-machine connections you need to account for network routing.
Bind to 0.0.0.0 instead of localhost:
go run . listen 0.0.0.0:5555
Then share your local IP address (e.g. 192.168.1.42) with your peer so they can connect to 192.168.1.42:5555.Find your local IP on Linux/macOS with:
ip route get 1 | awk '{print $7; exit}'
You will need to:
  1. Bind to 0.0.0.0:<port>.
  2. Allow the port through your system firewall (e.g. ufw allow 5555/tcp on Ubuntu).
  3. If behind a router, set up port forwarding for the chosen port to your machine’s local IP.
  4. Share your public IP address with your peer.
p2p-chat uses end-to-end encryption, but exposing a port to the internet still carries risk. Only share your address with trusted peers.
Any port from 1024 to 65535 works without elevated privileges. Port 5555 is the project default. Avoid ports already in use by other services.Check whether a port is free:
ss -tlnp | grep 5555

Expected terminal output

EventOutput
Listener startsListening on <address>
Peer connectsConnected
Encryption handshake completesEncryption established.
Peer quits gracefullyDisconnected

Build docs developers (and LLMs) love