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.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.
Starting the listener
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.Run the listen command
go run . listen localhost:5555 for you.Always provide an address
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.
Accepting connections from another machine on the same network
Accepting connections from another machine on the same network
Bind to Then share your local IP address (e.g.
0.0.0.0 instead of localhost: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:Accepting connections from the internet
Accepting connections from the internet
You will need to:
- Bind to
0.0.0.0:<port>. - Allow the port through your system firewall (e.g.
ufw allow 5555/tcpon Ubuntu). - If behind a router, set up port forwarding for the chosen port to your machine’s local IP.
- 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.
Choosing a port
Choosing a port
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:
Expected terminal output
| Event | Output |
|---|---|
| Listener starts | Listening on <address> |
| Peer connects | Connected |
| Encryption handshake completes | Encryption established. |
| Peer quits gracefully | Disconnected |