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.

Once a peer has started a listener, you connect to them by providing their address and port. The connection is established over TCP and an encryption handshake runs automatically before any messages are exchanged.

Connecting to a listener

1

Get the host's address

Ask your peer for the address they are listening on. It follows the format host:port, for example 192.168.1.42:5555 for a machine on the same network, or a public IP for an internet connection.
You must know the address before running the connect command. p2p-chat has no discovery mechanism — there is no way to browse for available hosts.
2

Run the connect command

go run . connect <address>
For example, to connect to a listener on the same machine:
go run . connect localhost:5555
Or use the convenience script included in the repository:
./connect.sh
The script runs go run . connect localhost:5555 for you.
3

Confirm the connection

If the host is reachable and listening, you will see:
Connected to localhost:5555
Encryption established.
You are now in an active chat session. Type a message and press Enter to send.

Connecting across machines

When your peer is on a different machine, replace localhost with their IP address.
Your peer runs:
go run . listen 0.0.0.0:5555
They share their local IP (e.g. 192.168.1.42). You run:
go run . connect 192.168.1.42:5555
Your peer shares their public IP address and has configured port forwarding on their router for the chosen port. You run:
go run . connect <public-ip>:5555
Replace <public-ip> with the address they gave you.
If the connection is refused or times out, ask your peer to verify that their firewall allows the port and that port forwarding is configured correctly.

Disconnect behavior

When the session ends, one of the following happens depending on how it terminates.
CauseYour terminalPeer’s terminal
Peer runs /quit!<nick> left the chat then DisconnectedDisconnecting... then process exits
You run /quitDisconnecting... then process exits!<nick> left the chat then Disconnected
Peer closes terminal abruptlyDisconnected (no leave message)
If the process does not exit automatically after a disconnect, press Ctrl+C to terminate it.

Expected terminal output

EventOutput
Connection succeedsConnected to <address>
Encryption handshake completesEncryption established.
Peer quits gracefullyDisconnected
Address unreachableGo runtime error (connection refused / timeout)

Build docs developers (and LLMs) love