Skip to content

Ayushsingh299/Multithreaded-Chat-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💬 Multithreaded Chat Application

A Java-based client-server chat system built using Sockets and Threads, where multiple clients can connect to a central server and exchange messages in real time. Supports broadcasting, private messaging, and concurrency handling

Java MySQL Tomcat License


📑 Table of Contents

1. 🎯 Overview

2. 📸 Screenshot

3. ✨ Features

4. 🛠️ Technologies Used

5. 🏗️ System Architecture

6. 📂 Project Structure

7. 🚀 Setup Instructions

8. 🎮 Running the Application

9. 📖 Usage Guide

10. 🗄️ Database Schema

11. 📡 API Documentation

12. 👥 Contributors

13. 🚀 Future Enhancements

14. 📄 License

15. 📞 Contact & Support

16. 🎓 Academic Context

17. 🏆 Conclusion

18. 🙏 Acknowledgments

19. 📚 References & Resources


🎯 Overview

The Multithreaded Chat Application is a scalable, full-stack Java web application that enables real-time communication between multiple users. It showcases advanced concepts including:

  • Concurrent programming with Java thread pools
  • Database integration using JDBC and DAO pattern
  • Web development with Servlets and JSP
  • Socket programming for real-time messaging
  • Modern UI features including dark/light theme toggle

Built as a comprehensive demonstration of Java enterprise application development, this project is ideal for academic portfolios, coding assessments, and real-world deployment scenarios.


📸 Screenshot

Registration Page

WhatsApp Image 2025-11-22 at 11 51 48_0b6983a3

Login Page

WhatsApp Image 2025-11-22 at 11 45 28_40188ca5

Chat Room

WhatsApp Image 2025-11-22 at 11 45 28_d8f3f2cb

✨ Features

Core Features

  • Real-time Messaging - Instant message delivery using socket connections
  • Broadcast Chat - Send messages to all connected users
  • Private Messaging - Direct messages to specific users
  • User Authentication - Secure login and registration system
  • Session Management - HTTP session tracking for web users
  • Persistent Storage - Messages and users stored in MySQL database

Advanced Features

  • 🌓 Dark/Light Theme - Toggle between themes with localStorage persistence
  • 🔐 Password Security - Hashed password storage
  • 📱 Responsive Design - Mobile-friendly web interface
  • 🧪 Unit Testing - JUnit test cases for critical components
  • 🔌 Dual Interface - Web UI and console-based client
  • Scalable Architecture - Thread pool handling 50+ concurrent connections

Technical Highlights

  • Multithreading: ExecutorService with fixed thread pool
  • Thread Safety: ConcurrentHashMap for client management
  • Exception Handling: Comprehensive error handling and logging
  • MVC Pattern: Clear separation of concerns
  • DAO Pattern: Database abstraction layer

🛠️ Technologies Used

Layer Technology Version Purpose
Backend Java 11+ Core application logic
Web Framework Servlets 4.0 HTTP request handling
View Layer JSP 2.3 Dynamic web pages
Database MySQL 8.0 Data persistence
JDBC MySQL Connector 8.0.33 Database connectivity
Build Tool Maven 3.6+ Dependency management
Server Apache Tomcat 9.0 Web application server
Testing JUnit 4.13 Unit testing
Frontend HTML5, CSS3, JavaScript - User interface

🏗️ System Architecture

image

📂 Project Structure

image image image

🚀 Setup Instructions

Prerequisites

Ensure you have the following installed:

  • Java JDK 11+ java -version

  • Apache Maven 3.6+ mvn -version

  • MySQL Server 8.0+ mysql --version

  • Apache Tomcat 9.0+

Installation Steps

1️⃣ Clone the Repository

git clone https://github.com/Ayushsingh299/Multithreaded-Chat-Application.git cd Multithreaded-Chat-Application

2️⃣ Setup MySQL Database

Login to MySQL mysql -u root -p

Create database and tables source database/schema.sql

Or manually: CREATE DATABASE chatapp; USE chatapp; -- Paste contents of schema.sql

3️⃣ Configure Database Connection

Edit src/main/java/com/chat/dao/ConnectionPool.java:

private static final String DB_URL = "jdbc:mysql://localhost:3306/chatapp"; private static final String DB_USER = "root"; private static final String DB_PASSWORD = "YOUR_PASSWORD_HERE"; // ⬅️ Change this!

4️⃣ Build the Project

mvn clean install

This will:

  • ✅ Compile all Java files
  • ✅ Run unit tests
  • ✅ Package as WAR file
  • ✅ Output: target/multithreaded-chat-application.war

5️⃣ Deploy to Tomcat

Option A: Manual cp target/multithreaded-chat-application.war $CATALINA_HOME/webapps/

Option B: Tomcat Manager

  • Go to http://localhost:8080/manager
  • Upload WAR file

6️⃣ Start Tomcat

Linux/Mac $CATALINA_HOME/bin/startup.sh

Windows %CATALINA_HOME%\bin\startup.bat


🎮 Running the Application

Web Interface

  1. Open browser and navigate to: http://localhost:8080/multithreaded-chat-application/

OR Use Online QR Code (Direct Link)

WhatsApp Image 2025-11-21 at 21 44 07_db3bc96e

  1. Login with sample credentials:
  • Username: admin | Password: admin123
  • Username: demo | Password: demo123
  1. Or register a new account and start chatting!

Socket Server (Optional - for Console Clients)

Navigate to compiled classes cd target/classes

Start socket server java com.chat.server.ChatServer

Expected output: ✓ Chat Server started on port 9999 ✓ Waiting for connections...

Console Client (Optional)

In another terminal java com.chat.client.ChatClient

Commands:

  • Type any message to broadcast to all
  • /private username message - Send private message
  • /help - Show available commands
  • /quit - Disconnect

📖 Usage Guide

Web Application Workflow

Registration

  1. Click "Register here" on login page
  2. Fill in:
    • Username (min 3 characters)
    • Email (valid format)
    • Password (min 6 characters)
    • Full Name (optional)
  3. Click "Register"
  4. Redirected to login page on success

Login

  1. Enter username and password
  2. Click "Login"
  3. On success, redirected to chat interface
  4. Session created (30 min timeout)

Chatting

  1. Type message in input box at bottom
  2. Press Enter or click "Send"
  3. Messages appear in chat window:
    • Your messages: Right side (green)
    • Other users: Left side (blue)
  4. Real-time updates (simulated in demo)

Theme Toggle

  1. Click 🌙 moon icon → Switch to dark mode
  2. Click ☀️ sun icon → Switch to light mode
  3. Preference saved in browser localStorage

Logout

  1. Click "Logout" in chat header
  2. Session invalidated
  3. Redirected to login page

🗄️ Database Schema

Users Table

CREATE TABLE users ( user_id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, full_name VARCHAR(100), is_online BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, INDEX idx_username (username), INDEX idx_email (email) ) ENGINE=InnoDB;

Messages Table

CREATE TABLE messages ( message_id INT PRIMARY KEY AUTO_INCREMENT, sender_id INT NOT NULL, recipient_id INT NULL, -- NULL for broadcast content TEXT NOT NULL, sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (sender_id) REFERENCES users(user_id) ON DELETE CASCADE, INDEX idx_sender (sender_id), INDEX idx_sent_at (sent_at) ) ENGINE=InnoDB;

Entity Relationship Diagram

image

📡 API Documentation

Servlet Endpoints

Endpoint Method Parameters Response Description
/login GET - login.jsp Display login form
/login POST username, password Redirect to chat Authenticate user
/register GET - register.jsp Display registration form
/register

👥 Contributors

This project was developed as part of a collaborative team effort for academic coursework, demonstrating full-stack Java development skills.

Ayush Singh
Ayush Singh

Backend & Database
🔧 Socket Server | 💾 JDBC/DAO | 🧵 Multithreading
Aayush Gaira
Aayush Gaira

Frontend & Web Integration
🌐 JSP/Servlets | 📱 Responsive UI | 🎨 HTML/CSS
Rehan Chaudhary
Rehan Chaudhary

UI/UX Design & Testing
🎨 Theme Design | 🧪 Testing | 📝 Documentation

Contribution Breakdown

Contributor Primary Responsibilities Technologies
Ayush Singh Socket server architecture, multithreading implementation, database schema design, JDBC integration, DAO pattern implementation Java, MySQL, JDBC, Multithreading, Sockets
Aayush Gaira Servlet development, JSP page creation, web application flow, session management, MVC implementation Java Servlets, JSP, HTML, JavaScript
Rehan Chaudhary CSS styling, dark/light theme, UI components, user experience design, documentation, testing CSS3, JavaScript, UI/UX Design

Language Distribution

Java ████████████████████░░ 40% (Server, DAO, Models, Servlets)

JSP/HTML ██████████░░░░░░░░░░░ 25% (Web pages, UI templates)

CSS ██████░░░░░░░░░░░░░░ 15% (Styling, Layout, Themes)

JavaScript ██████░░░░░░░░░░░░░░ 15% (Client-side logic, UI actions)

SQL ██░░░░░░░░░░░░░░░░░ 5% (Database operations)

🚀 Future Enhancements

Planned Features

  • WebSocket Integration - Real-time bidirectional communication
  • File Sharing - Upload and share images, documents
  • Emoji Picker - Enhanced messaging with emojis and reactions
  • Group Chat Rooms - Create and join multiple chat rooms
  • User Presence - Online/offline/away status indicators
  • Message Notifications - Desktop and browser notifications
  • Message History - Load and search previous messages
  • User Profiles - Avatar, bio, status customization
  • Voice/Video Calls - WebRTC integration
  • Message Encryption - End-to-end encryption (E2EE)
  • Mobile App - Android/iOS native applications
  • Admin Dashboard - User management, analytics
  • Read Receipts - Message delivery and read status
  • Typing Indicators - Show when users are typing

Technical Improvements

  • Implement BCrypt for password hashing
  • Add Redis for session management and caching
  • Implement connection pooling with HikariCP
  • Add comprehensive logging (Log4j/SLF4J)
  • Implement rate limiting and DDoS protection
  • Add API documentation with Swagger
  • Implement CI/CD pipeline (Jenkins/GitHub Actions)
  • Add load testing (JMeter)
  • Dockerize the application
  • Deploy to cloud (AWS/Azure/GCP)

📄 License

MIT License

Copyright (c) 2025 Ayush Singh, Aayush Gaira, Rehan Chaudhary

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


📞 Contact & Support

Get in Touch

Contributors


🎓 Academic Context

This project was developed as part of a Java Web Development course, demonstrating:

Learning Objectives Achieved

Core Java Concepts

  • Object-Oriented Programming (Encapsulation, Inheritance, Polymorphism)
  • Collections Framework (ConcurrentHashMap, ArrayList)
  • Exception Handling (try-catch-finally, custom exceptions)
  • Multithreading (ExecutorService, Thread pools, Synchronization)

Database Integration

  • JDBC connectivity and connection management
  • DAO (Data Access Object) pattern
  • CRUD operations with PreparedStatements
  • Transaction handling
  • Database schema design and normalization

Web Technologies

  • Servlet API for request/response handling
  • JSP for dynamic web pages
  • Session management and cookies
  • MVC architectural pattern
  • HTTP protocol understanding

Software Engineering Practices

  • Version control with Git
  • Unit testing with JUnit
  • Code documentation
  • Project structure and organization
  • Collaborative development

Project Criteria Fulfillment

Criteria Implementation Score
Problem Understanding Architecture diagrams, clear requirements ⭐⭐⭐⭐⭐
Core Java Concepts OOP, Collections, Threading, Exception Handling ⭐⭐⭐⭐⭐
Database Integration JDBC, DAO pattern, Schema design ⭐⭐⭐⭐⭐
Servlets & Web Request/Response, Session management ⭐⭐⭐⭐⭐
Code Quality Clean code, testing, documentation ⭐⭐⭐⭐⭐
Innovation Theme toggle, dual interface, scalability ⭐⭐⭐⭐⭐

🏆 Conclusion

The Multithreaded Chat Application successfully demonstrates a comprehensive understanding of enterprise Java development, showcasing:

Key Achievements

  1. Scalable Architecture - Thread pool manages 50+ concurrent connections efficiently
  2. Database Integration - Robust JDBC implementation with DAO pattern
  3. Real-time Communication - Socket programming for instant messaging
  4. Modern Web Development - Servlets, JSP, and session management
  5. User Experience - Dark/light theme, responsive design
  6. Code Quality - Clean architecture, unit tests, comprehensive documentation

Technical Excellence

  • Concurrency Handling: ExecutorService thread pool with proper synchronization
  • Data Persistence: MySQL database with normalized schema
  • Security: Session management, input validation, prepared statements
  • Maintainability: MVC pattern, DAO abstraction, modular design
  • Testability: JUnit tests, separation of concerns

Real-World Applicability

This project serves as a solid foundation for:

  • Enterprise chat applications
  • Customer support systems
  • Real-time collaboration tools
  • Learning management systems
  • Social networking platforms

Learning Outcomes

Through this project, we gained hands-on experience with:

  • Backend Development: Java, JDBC, Socket programming
  • Frontend Development: JSP, HTML, CSS, JavaScript
  • Database Design: MySQL, SQL, normalization
  • Software Architecture: Design patterns, scalability
  • Team Collaboration: Git, code reviews, documentation

🙏 Acknowledgments

Special thanks to:

  • Course Instructors for guidance on Java enterprise development
  • Open Source Community for tools and libraries (MySQL, Tomcat, Maven)
  • Stack Overflow for troubleshooting and best practices
  • GitHub for version control and collaboration platform

📚 References & Resources

Documentation

Tutorials

Tools


⭐ If you found this project helpful, please give it a star!

Made with ☕ and 💻 by CS Students

.Report Bug · Request Feature

© 2025 Multithreaded Chat Application. All Rights Reserved.

About

A Java-based client-server chat system built using Sockets and Threads, where multiple clients can connect to a central server and exchange messages in real time. Supports broadcasting, private messaging, and concurrency handling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors