Skip to content

SocketChatApp is a C++-based client-server chat application built using Winsock for socket communication and multithreading for concurrency. It was developed to understand low-level Windows network programming and real-time message handling.

Notifications You must be signed in to change notification settings

Dipukumar1997/SocketChatApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Socket Chat App ๐Ÿ’ฌ

A simple yet efficient real-time chat application implemented in C++ using socket programming. This application consists of a server and client component that enables multiple users to communicate in real-time over a network.

๐ŸŒŸ Features

  • Real-time Communication: Direct TCP socket communication between server and clients
  • Multi-client Support: Server can handle multiple simultaneous client connections
  • Cross-platform Compatibility: Works on Linux, Windows, and macOS
  • Lightweight: Minimal resource usage with native C++ implementation
  • Console-based Interface: Simple terminal-based chat interface
  • Thread-safe Operations: Proper handling of concurrent client connections

๐Ÿš€ Technologies Used

  • Language: C++
  • Networking: TCP Sockets (Berkeley sockets / Winsock)
  • Threading: POSIX threads (pthread) / Windows threads
  • Build System: Make / CMake (depending on your setup)

๐Ÿ“‹ Prerequisites

Linux/macOS

  • GCC compiler (g++) version 7.0 or higher
  • POSIX-compliant system
  • Make utility

Windows

  • MinGW-w64 or Visual Studio with C++ support
  • Windows SDK (for Winsock)

โšก Quick Start

1. Clone the Repository

git clone https://github.com/Dipukumar1997/SocketChatApp.git
cd SocketChatApp

2. Compile the Programs

Linux/macOS:

# Compile server
g++ -o server server.cpp -lpthread

# Compile client
g++ -o client client.cpp -lpthread

Windows (MinGW):

# Compile server
g++ -o server.exe server.cpp -lws2_32

# Compile client
g++ -o client.exe client.cpp -lws2_32

3. Run the Application

Start the Server:

./server
# or on Windows: server.exe

Connect Clients:

./client
# or on Windows: client.exe

๐Ÿ“ Project Structure

SocketChatApp/
โ”œโ”€โ”€ server.cpp            # Server implementation
โ”œโ”€โ”€ client.cpp            # Client implementation
โ”œโ”€โ”€ README.md             # Project documentation
โ””โ”€โ”€ LICENSE               # License file 

๐Ÿ’ป Usage

Starting the Chat System

  1. Start the Server First:

    ./server

    The server will start listening on a default port (usually 8080 or as configured).

  2. Connect Multiple Clients:

    ./client

    Each client will prompt for connection details and username.

  3. Start Chatting:

    • Type messages in any client terminal
    • Messages will be broadcasted to all connected clients
    • Use special commands (if implemented) like /quit to exit

Configuration

Server Configuration

The server typically uses these default settings:

  • Port: 8080 (see the console for {PORT})
  • Max Connections: 10 (or as configured)
  • Buffer Size: 1024 bytes (or as defined)

Client Configuration

  • Server IP: localhost/127.0.0.1 (default)
  • Server Port: Must match server port
  • Username: Prompted during connection

๐Ÿ”ง Customization

Modifying Connection Parameters

In server.cpp:

#define PORT 8080           // Change server port
#define MAX_CLIENTS 10      // Maximum concurrent clients
#define BUFFER_SIZE 1024    // Message buffer size

In client.cpp:

#define SERVER_IP "127.0.0.1"  // Server IP address
#define PORT 8080              // Server port (must match server)
#define BUFFER_SIZE 1024       // Message buffer size

๐Ÿงช Testing

Basic Functionality Test

  1. Single Client Test:

    # Terminal 1
    ./server
    
    # Terminal 2
    ./client
  2. Multiple Clients Test:

    # Terminal 1: Server
    ./server
    
    # Terminal 2: Client 1
    ./client
    
    # Terminal 3: Client 2
    ./client
    
    # Terminal 4: Client 3
    ./client
  3. Network Test:

    • Run server on one machine
    • Connect clients from different machines on the same network
    • Update client.cpp with server's actual IP address

๐Ÿ› Troubleshooting

Common Issues

Connection Refused:

  • Ensure server is running before starting clients
  • Check if the port is already in use
  • Verify firewall settings

Compilation Errors:

# Linux: Install build essentials
sudo apt-get install build-essential

# Missing pthread library
sudo apt-get install libc6-dev

Windows Socket Errors:

  • Ensure Winsock2 is properly linked (-lws2_32)
  • Check Windows Defender firewall settings

Debug Mode

Compile with debug flags for troubleshooting:

g++ -g -DDEBUG -o server server.cpp -lpthread
g++ -g -DDEBUG -o client client.cpp -lpthread

๐Ÿš€ Deployment

Local Network Deployment

  1. Configure Server IP:

    • Find server machine's IP address: ifconfig (Linux/Mac) or ipconfig (Windows)
    • Update client.cpp with the server's IP address
  2. Firewall Configuration:

    • Open the port used by the server (default 8080)
    • Allow incoming connections for the server application
  3. Run Across Network:

    # On server machine
    ./server
    
    # On client machines
    ./client

๐Ÿ“š Code Architecture

Server Architecture

  • Main Thread: Accepts incoming connections
  • Client Threads: Handle individual client communication
  • Broadcast Function: Sends messages to all connected clients
  • Connection Management: Maintains list of active clients

Client Architecture

  • Main Thread: Handles user input
  • Receive Thread: Listens for incoming messages from server
  • Send Function: Sends user messages to server

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/new-feature
  3. Make your changes:
    • Follow C++ best practices
    • Add comments for complex logic
    • Test thoroughly on different platforms
  4. Commit your changes:
    git commit -m "Add new feature: description"
  5. Push and create a Pull Request

Coding Standards

  • Use consistent indentation (4 spaces or tabs)
  • Follow C++ naming conventions
  • Add error handling for socket operations
  • Include comments for complex algorithms
  • Test on both Linux and Windows if possible

๐Ÿ”ฎ Future Enhancements

  • GUI interface using Qt or GTK
  • Private messaging between specific users
  • File transfer capabilities
  • Message encryption (SSL/TLS)
  • User authentication system
  • Chat rooms/channels
  • Message history logging
  • Configuration file support
  • IPv6 support
  • Reconnection handling

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Dipu Kumar

๐Ÿ™ Acknowledgments

  • C++ Socket Programming tutorials and documentation
  • POSIX threading documentation
  • Winsock API documentation
  • Open source community for inspiration and best practices

๐Ÿ“ž Support

If you encounter issues:

  1. Check the Issues section
  2. Create a new issue with:
    • Operating system and version
    • Compiler version
    • Error messages or unexpected behavior
    • Steps to reproduce the problem

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

About

SocketChatApp is a C++-based client-server chat application built using Winsock for socket communication and multithreading for concurrency. It was developed to understand low-level Windows network programming and real-time message handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages