A lightweight, multi-threaded terminal chat application built with C++ and TCP sockets
Features โข Quick Start โข Installation โข Usage โข Documentation
TerminalTalk is a real-time, multi-client chat application that runs entirely in your terminal. Built from scratch using C++ and POSIX sockets, it demonstrates advanced networking concepts including multi-threading, socket programming, and concurrent client handling[web:11][web:20].
- โก Blazing Fast - Pure C++ implementation with minimal overhead
- ๐งต Multi-Threaded - Handle unlimited clients simultaneously
- ๐ Thread-Safe - Mutex-protected shared resources
- ๐ฆ Zero Dependencies - Only standard C++ libraries
- ๐ Educational - Clean, well-documented code for learning
- ๐ ๏ธ Easy Build - One command compilation with Makefile
- โ Real-Time Messaging - Instant message delivery via TCP
- โ Multi-Client Support - Connect unlimited users simultaneously
- โ Username System - Unique usernames for each participant
- โ Broadcast Messages - All messages sent to every connected client
- โ Join/Leave Notifications - Server announces user activity
- โ
Graceful Disconnect - Clean exit with
/quitor/exitcommands - โ Automatic Cleanup - Handles disconnections and crashes elegantly
- Multi-threaded server architecture
- POSIX socket programming
- Mutex-based synchronization
- Thread-safe client management
- Non-blocking I/O operations
- Automatic port reuse
NOTE: Final Update From Me!
Clone the repository
git clone https://github.com/suadatbiniqbal/TerminalTalk-TCP-Servewr.git cd TerminalTalk-TCP-Servewr Build everything
make Terminal 1: Start server
./server Terminal 2: Connect first client
./client Terminal 3: Connect second client
./client
text
That's it! Start chatting ๐
- OS: Linux, macOS, or WSL2
- Compiler: GCC/G++ 4.8.1+ with C++11 support
- Build Tool: Make (optional but recommended)
g++ --version # Should show 4.8.1 or higher make --version # Check if Make is installed
text
Clone repository
git clone https://github.com/suadatbiniqbal/TerminalTalk-TCP-Servewr.git cd TerminalTalk-TCP-Servewr Build both server and client
make
text
Compile server
g++ -std=c++11 -pthread server.cpp -o server Compile client
g++ -std=c++11 -pthread client.cpp -o client
text
Build and install to /usr/local/bin
make install Now run from anywhere
server # Start server client # Connect client
text
make run-server OR
./server
text
Output:
[SERVER] Server is listening on port 5555 [SERVER] Waiting for connections...
text
Terminal 2:
make run-client OR
./client
text
You'll see:
Enter your username: Alice [CLIENT] Connected to server at 127.0.0.1:5555 [CLIENT] Type /quit or /exit to disconnect
[SERVER] Welcome Alice! You are now connected. Alice:
text
Alice:
Alice: Hey everyone! ๐ [SERVER] Bob has joined the chat! Bob: Hi Alice! How's it going? Alice: Great! Welcome Bob!
text
Bob:
Enter your username: Bob [SERVER] Welcome Bob! You are now connected. Alice: Hey everyone! ๐ Bob: Hi Alice! How's it going? Alice: Great! Welcome Bob!
text
| Command | Description |
|---|---|
make |
Build both server and client |
make all |
Same as make |
make server |
Build server only |
make client |
Build client only |
make clean |
Remove all build files |
make rebuild |
Clean and rebuild everything |
make run-server |
Build and run server |
make run-client |
Build and run client |
make install |
Install system-wide (requires sudo) |
make uninstall |
Remove system installation |
make help |
Show all available commands |
| Command | Description | Example |
|---|---|---|
/quit |
Disconnect from server | /quit |
/exit |
Disconnect (alternative) | /exit |
Ctrl+C |
Force disconnect | - |
text โโโโโโโโโโโโโโโโโโโโโโโ โ TCP Server โ โ Port: 5555 โ โ Multi-threaded โ โโโโโโโโโโโโฌโโโโโโโโโโโ โ โโโโโโโโโโโโโผโโโโโโโโโโโโฌโโโโโโโโโโโโ โ โ โ โ
โโโโโผโโโโ โโโโผโโโโ โโโโโผโโโโ โโโโผโโโโ โClient1โ โClient2โ โClient3โ โClient4โ โ Alice โ โ Bob โ โ Charlieโ โ Davidโ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโโ โโโโโโโโโ
text
- Connection: Client connects to server (port 5555)
- Authentication: Server requests username
- Registration: Client sends username, added to active list
- Broadcasting: Server announces new user to all clients
- Messaging: User sends message โ Server broadcasts to all
- Disconnection: User leaves โ Server notifies everyone
TerminalTalk-TCP-Servewr/ โโโ server.cpp # Server implementation โโโ client.cpp # Client implementation โโโ Makefile # Build automation โโโ README.md # This file โโโ LICENSE # MIT License
text
Edit server.cpp and client.cpp:
#define PORT 8080 // Change to your preferred port
text
Edit client.cpp:
#define SERVER_IP "192.168.1.100" // Your server's IP address
text
Edit server.cpp:
#define MAX_CLIENTS 50 // Increase for more users
text
Edit both files:
#define BUFFER_SIZE 2048 // For longer messages
text
Then rebuild:
make rebuild
text
Problem: [ERROR] Connection failed. Make sure the server is running.
Solution:
Ensure server is running first
./server Check if port is available
netstat -tuln | grep 5555
text
Problem: [ERROR] Bind failed
Solution:
Find process using port 5555
lsof -i :5555 Kill the process
kill -9 Or use make to rebuild
make rebuild
text
Problem: error: 'thread' is not a member of 'std'
Solution:
Ensure C++11 support
make clean make
text
Problem: [ERROR] Username must be at least 2 characters long
Solution: Enter a username with 2+ characters
Problem: Permission errors during make install
Solution:
sudo make install
text
Contributions make the open-source community an amazing place to learn and create. Any contributions are greatly appreciated!
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Private messaging (
/msg username message) - Chat rooms/channels
- Message encryption (TLS/SSL)
- File transfer support
- Message history/logging
- User authentication system
- Admin commands (kick, ban, mute)
- Emoji support
- Message timestamps
- Color-coded messages
- GUI version (Qt/GTK)
- Windows support (Winsock)
Server Functions:
broadcast_message()- Send message to all clients except senderhandle_client()- Manage individual client connectionsremove_client()- Clean up disconnected clients
Client Functions:
receive_messages()- Listen for incoming messages (thread)send_messages()- Handle user input and send (thread)connect_to_server()- Establish connection with server
Free Open Source
Suadat Bin Iqbal
- GitHub: @suadatbiniqbal
- Project: TerminalTalk-TCP-Servewr
- GeeksforGeeks - Socket programming tutorials
- Beej's Guide - Network programming guide
- POSIX Threads - Threading tutorials
- Shields.io - README badges
- Best-README-Template - README inspiration
Made with Hate BY suadat
โญ Star this repo if you found it helpful! โญ