A simple peer-to-peer UDP chat application for Windows written in C++.
- Real-time messaging over UDP
- Peer-to-peer communication
- Preserves partially typed input when messages arrive
- Graceful shutdown using
Ctrl+C - No central server required
- No third-party dependencies
- Windows 10 or newer
Any C++17-compatible Windows compiler.
Tested with:
- MinGW-w64
Should also work with:
- Microsoft Visual Studio (MSVC)
- MSYS2 UCRT64
- MSYS2 MINGW64
Only standard Windows libraries are required:
- Winsock2 (
ws2_32) - Windows Console API
No external dependencies are needed.
git clone https://github.com/acdhemtos/udp-chat.git
cd udp-chat
cd code
g++ main.cpp network.cpp console.cpp -o ../chat.exe -std=c++17 -lws2_32
cd ../The Compiler specific command may be different.
The application accepts three command-line arguments:
chat.exe <local_port> <peer_ip> <peer_port>
| Parameter | Description |
|---|---|
| local_port | Port this instance listens on |
| peer_ip | IP address of the remote peer |
| peer_port | Port the remote peer listens on |
Open two terminal windows.
chat.exe 5000 127.0.0.1 5001chat.exe 5001 127.0.0.1 5000Messages typed in either terminal will appear in the other.
You can exit the application by pressing Ctrl+C.
Because UDP is connectionless:
- Delivery is not guaranteed.
- Packets may arrive out of order.
- Packets may be lost.
- There is no retransmission mechanism.
The first time the application runs, Windows Firewall may display a prompt.
If you want to communicate across machines, allow access on the desired network type.
Assume:
| Machine | IP Address |
|---|---|
| A | 192.168.1.10 |
| B | 192.168.1.25 |
chat.exe 5000 192.168.1.25 5001chat.exe 5001 192.168.1.10 5000Both machines must:
- Be reachable on the network
- Allow UDP traffic through the firewall
- Use matching peer ports
Current version does not include:
- Message delivery guarantees
- Encryption
- Authentication
- Usernames
- File transfer
- Group chat
- Message history
