A simple multithreaded chat application in Java using sockets.
- Multiple clients can connect to the server
- Unique usernames (handshake on connection)
- Public chat (message broadcasting)
- Private messaging (
/pm) - Notifications when users join or leave
- Multithreading (each client handled in a separate thread)
- Starts the server on port
4045 - Accepts incoming connections
- Passes clients to a thread pool
- Handles a single client
- Reads and sends messages
- Processes commands (
/pm,END,/exit)
- Stores connected clients
- Sends messages to all clients (broadcast)
- Handles private messaging
- Client-side application
- Sends messages to the server
- Reads incoming messages in a separate thread
- Dedicated thread for reading messages from the server
run Server.main()Expected output:
start
Run multiple instances:
run Main.main()Allow multiple instances
After connecting:
Enter your name:
The username must be unique.
Hello everyone
Result:
Denis: Hello everyone
/pm Alex Hi!
Result:
For the receiver:
[PM] Denis: Hi!
For the sender:
[PM to Alex]: Hi!
/exit
Recommended setup:
- 1 server
- 2–5 clients
Test the following:
- message broadcasting
- private messaging
- duplicate username handling
- client disconnection
- Java Core
- Sockets (TCP)
- Multithreading (ExecutorService)
- Collections (CopyOnWriteArrayList)
-
/userscommand (list of online users) - Message timestamps
- GUI (Swing)
- Web version (Servlets / HTTP)
- REST API
- WebSocket chat
- Working with sockets
- Multithreading
- Client-server architecture
- Command handling
- Thread synchronization
Denys Burduzhan
This project was created for learning purposes to practice Java Core, networking, and multithreading.