A Java project that implements a simple live chat room using Multi-threading and a MySQL database for storing and retrieving messages. The application runs in the terminal and uses ANSI codes for colorized, real-time message updates.
- Core Language: Java
- Database: MySQL
- Connectivity: JDBC (Java Database Connectivity)
- Concurrency: Uses a separate
Thread(MessageFetch) for real-time polling.
- Real-time Messaging: Uses multi-threading to poll and display messages instantly.
- User Identification: ANSI colorized usernames for visual distinction.
- Database Persistence: All chats are stored in a MySQL database with auto-timestamps.
- Easter Eggs & Commands: Special commands for fun visuals and utilities.
- Gemini Integration: Chat directly with an AI bot (Gemini 2.5 Flash). Allowing for more enhanced user experience with the application.
Use these commands inside the Live Chat to trigger special effects:
/weather <city>: Fetches current weather for the specified city (e.g.,/weather Mangalore)./list: Lists all available ASCII art commands.- ASCII Art:
/red,/butterfly,/aah,/dance,/kitty
Enter username: Devdat
Select mode:
1. Live Chat
2. AI Chat
Enter choice: 1
Attempting to connect to server...
Connection successful!
--- Chat room (Live) ---
[21:30:00] Devdat : Hey everyone, this chat finally works!
[21:31:10] Pramukh : Nice! I was just testing the system.
>
Before running, you must set up the Chatapp database and create a table for messages.
| Component | SQL Type | Description |
|---|---|---|
id |
INT (PK, AUTO_INCREMENT) |
Primary key, used by the Java application to track new messages. |
username |
VARCHAR |
The user's chosen display name. |
message_text |
VARCHAR |
The content of the message. |
color_code |
VARCHAR |
ANSI code for username color. |
timestamp |
DATETIME / TIMESTAMP |
Timestamp of the message (set by the database). |
CREATE DATABASE IF NOT EXISTS Chatapp;
USE Chatapp;
CREATE TABLE messages (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
message_text TEXT NOT NULL,
color_code VARCHAR(15),
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);- Clone the Repository:
git clone https://github.com/devdat2021/CLI-Chat cd CLI-Chat - Download JDBC Driver: Ensure you have the MySQL JDBC Connector (
mysql-connector-java-[version].jar) and place it in a location accessible to your build system. - Update credentials: Ensure you change the API Key, DB Connection info with your actual information before compiling.
- Compile: Compile the Java files (
App.java,message.java,DBConnection.java,LiveChat.java,AIChat.java,extra.java,). - Run: Execute the compiled
Appclass, ensuring the JDBC driver is on the classpath.