Skip to content

suadatbiniqbal/TerminalTalk-TCP-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TerminalTalk TCP Server ๐Ÿ’ฌ

C++ Socket TCP Linux Make License

A lightweight, multi-threaded terminal chat application built with C++ and TCP sockets

Features โ€ข Quick Start โ€ข Installation โ€ข Usage โ€ข Documentation

Demo Version


๐ŸŽฏ About

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].

๐Ÿš€ Why TerminalTalk?

  • โšก 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

โœจ Features

Core Functionality

  • โœ… 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 /quit or /exit commands
  • โœ… Automatic Cleanup - Handles disconnections and crashes elegantly

Technical Features

  • Multi-threaded server architecture
  • POSIX socket programming
  • Mutex-based synchronization
  • Thread-safe client management
  • Non-blocking I/O operations
  • Automatic port reuse

โšก Quick Start

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 ๐ŸŽ‰


๐Ÿ”ง Prerequisites

  • OS: Linux, macOS, or WSL2
  • Compiler: GCC/G++ 4.8.1+ with C++11 support
  • Build Tool: Make (optional but recommended)

Verify Installation

g++ --version # Should show 4.8.1 or higher make --version # Check if Make is installed

text


๐Ÿ“ฅ Installation

Method 1: Using Makefile (Recommended)

Clone repository

git clone https://github.com/suadatbiniqbal/TerminalTalk-TCP-Servewr.git cd TerminalTalk-TCP-Servewr Build both server and client

make

text

Method 2: Manual Compilation

Compile server

g++ -std=c++11 -pthread server.cpp -o server Compile client

g++ -std=c++11 -pthread client.cpp -o client

text

Method 3: System-Wide Installation

Build and install to /usr/local/bin

make install Now run from anywhere

server # Start server client # Connect client

text


๐Ÿš€ Usage

Starting the Server

make run-server OR

./server

text

Output:

[SERVER] Server is listening on port 5555 [SERVER] Waiting for connections...

text

Connecting Clients

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

Example Chat Session

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


๐Ÿ“ Makefile Commands

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

๐ŸŽฎ Chat Commands

Command Description Example
/quit Disconnect from server /quit
/exit Disconnect (alternative) /exit
Ctrl+C Force disconnect -

๐Ÿ—๏ธ Architecture

System Design

text โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ TCP Server โ”‚ โ”‚ Port: 5555 โ”‚ โ”‚ Multi-threaded โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚

โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”‚Client1โ”‚ โ”‚Client2โ”‚ โ”‚Client3โ”‚ โ”‚Client4โ”‚ โ”‚ Alice โ”‚ โ”‚ Bob โ”‚ โ”‚ Charlieโ”‚ โ”‚ Davidโ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

text

Data Flow

  1. Connection: Client connects to server (port 5555)
  2. Authentication: Server requests username
  3. Registration: Client sends username, added to active list
  4. Broadcasting: Server announces new user to all clients
  5. Messaging: User sends message โ†’ Server broadcasts to all
  6. Disconnection: User leaves โ†’ Server notifies everyone

File Structure

TerminalTalk-TCP-Servewr/ โ”œโ”€โ”€ server.cpp # Server implementation โ”œโ”€โ”€ client.cpp # Client implementation โ”œโ”€โ”€ Makefile # Build automation โ”œโ”€โ”€ README.md # This file โ””โ”€โ”€ LICENSE # MIT License

text


โš™๏ธ Configuration

Change Server Port

Edit server.cpp and client.cpp:

#define PORT 8080 // Change to your preferred port

text

Change Server IP (Remote Connection)

Edit client.cpp:

#define SERVER_IP "192.168.1.100" // Your server's IP address

text

Adjust Maximum Clients

Edit server.cpp:

#define MAX_CLIENTS 50 // Increase for more users

text

Adjust Buffer Size

Edit both files:

#define BUFFER_SIZE 2048 // For longer messages

text

Then rebuild:

make rebuild

text


๐Ÿ” Troubleshooting

โŒ Connection Refused

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

โŒ Port Already in Use

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

โŒ Compilation Errors

Problem: error: 'thread' is not a member of 'std'

Solution:

Ensure C++11 support

make clean make

text

โŒ Username Too Short

Problem: [ERROR] Username must be at least 2 characters long

Solution: Enter a username with 2+ characters

โŒ Permission Denied (Install)

Problem: Permission errors during make install

Solution:

sudo make install

text


๐Ÿค Contributing

Contributions make the open-source community an amazing place to learn and create. Any contributions are greatly appreciated!

How to Contribute

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Feature Ideas ๐Ÿ’ก

  • 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)

๐Ÿ“š Documentation

Server Functions:

  • broadcast_message() - Send message to all clients except sender
  • handle_client() - Manage individual client connections
  • remove_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

Learning Resources


๐Ÿ“„ License

Free Open Source


๐Ÿ‘ค Author

Suadat Bin Iqbal


๐Ÿ™ Acknowledgments


๐Ÿ“Š Project Stats

GitHub repo size GitHub stars GitHub forks GitHub issues


Made with Hate BY suadat

โญ Star this repo if you found it helpful! โญ

Report Bug โ€ข Request Feature