A simple two-peer terminal chat application written in C.
The project uses TCP sockets for communication and POSIX threads to handle sending and receiving messages concurrently. One peer starts the application in host mode and waits for a connection, while the other starts it in client mode and connects to the host.
- TCP-based communication
- Two-peer terminal chat
- Simultaneous sending and receiving of messages
- POSIX threads for concurrent I/O
- Separate host and client modes
- POSIX-compatible system
- GCC
Clone the repository and build the project:
git clone https://github.com/cldprgm/peerchat.git
cd peerchat
makeThe executable will be created as:
./chat
To remove build artifacts:
make cleanTo perform a clean rebuild:
make reThe host listens for an incoming TCP connection:
./chat -m hostBy default, port 8082 is used.
A custom port can be specified with -p:
./chat -m host -p 9000The client connects to the host using its IPv4 address:
./chat -m client -ip 127.0.0.1A custom port can also be specified:
./chat -m client -ip 127.0.0.1 -p 9000| Option | Description |
|---|---|
-m host |
Start in host mode |
-m client |
Start in client mode |
-ip ADDRESS |
IPv4 address of the host |
-p PORT |
TCP port, from 1 to 65535 |
Start the host in one terminal:
./chat -m hostThen start the client in another terminal:
./chat -m client -ip 127.0.0.1Once connected, both peers can exchange messages through the terminal.
args.c
Parses and validates command-line arguments.
network.c
Handles TCP sockets, connections, sending, and receiving messages.
chat.c
Implements the chat logic, terminal input, and background threads.
main.c
Initializes the application and selects the host or client mode.
- POSIX sockets
- TCP/IP
- POSIX threads (
pthread) - termios
This project is intentionally simple and currently supports:
- one connection per host
- two peers only
- IPv4 addresses
- terminal-based communication
It does not currently provide encryption, multiple simultaneous clients, message history, or a graphical interface.
This project is available under the MIT License.