A Java desktop client–server chat application with role-based access control, WhatsApp-themed GUI, and text-file logging.
- User Authentication: Login via credentials file with ADMIN/GENERAL roles
- Online Presence: Real-time online/offline status tracking
- Private & Group Chat: One-to-one and group conversations
- WhatsApp-themed GUI: Modern, user-friendly interface
- Notifications: Popup notifications for new messages
- Logging & Persistence: All sessions and messages logged to text files
src/
├── common/ # Shared classes (User, Message, Enums)
├── server/ # Server-side code
│ ├── Server.java # Main server with ClientHandler
│ ├── Authentication.java # Credential validation
│ ├── ConnectionManager.java # Socket/stream management
│ ├── ChatManager.java # Chat session management
│ ├── ChatSession.java # Individual chat sessions
│ ├── Logger.java # File logging
│ └── UserSession.java # User session tracking
└── client/ # Client-side code
├── AuthGUI.java # Login window (with main method)
├── ClientGUI.java # Main chat interface
├── ClientConnection.java # Network client
└── Notification.java # Message notifications
data/
├── credentials.txt # User credentials (username,password,role)
└── chat_log.txt # Combined log file (messages and sessions)
From the project root directory:
# Create output directory
mkdir -p out
# Compile all Java files
javac -d out -cp . src/common/*.java src/server/*.java src/client/*.javaEnsure the data/ directory exists with:
credentials.txt: Formatusername,password,role(one per line)- Example:
alice,alice123,GENERAL
- Example:
chat_log.txt: Empty initially (auto-created)sessions.txt: Empty initially (auto-created)
On the server machine:
# Default port 1234
java -cp out server.Server
# Or specify a port
java -cp out server.Server 1234The server will:
- Listen for client connections
- Authenticate users from
data/credentials.txt - Route messages between clients
- Log all sessions and messages to text files
On each client machine:
java -cp out client.AuthGUIIn the login window:
- Enter username and password (from credentials file)
- Enter server host (IP address or hostname of server machine)
- Enter server port (default: 1234)
- Click Login
- Login: Enter credentials and server address
- View Contacts: Left panel shows online users
- Start Chat: Click a user to start a private chat
- Create Group: Click "New Group", select users, enter group name
- Send Messages: Type in the input field and click "Send"
- View History: Previous messages load automatically when opening a chat
- Admins see a "View Logs" button (visible only to ADMIN role)
- All other features same as general users
- Server: Runs on one machine, listens on specified port (default 1234)
- Clients: Connect to server IP/port from their own machines
- Protocol: Uses Java ObjectInputStream/ObjectOutputStream for serialized Message objects
username,password,role
alice,alice123,GENERAL
bob,bob123,ADMIN
MESSAGE|messageID|chatID|senderID|timestamp|content
SESSION|chatID|timestamp|isGroup|participant1,participant2,...|chatName
- Connection refused: Check server is running and firewall allows the port
- Login failed: Verify credentials in
data/credentials.txt - User already logged in: Only one session per user allowed
- Messages not appearing: Check server console for errors
Messageclass isSerializablefor network transmissionUserandChatSessionare alsoSerializablefor session data- Server uses multi-threaded
ClientHandlerfor each connected client - Client uses
ClientConnectionwith listener pattern for async message handling ConnectionManagercreates and managesObjectInputStream/ObjectOutputStreamfor each client- All logs (messages and sessions) are stored in a single
chat_log.txtfile withMESSAGE|andSESSION|prefixes