A comprehensive network programming project demonstrating 5 key Java networking concepts through an interactive quiz application.
This project implements a real-time, multi-client quiz system where multiple players can connect to a central server, answer questions simultaneously, and compete for the highest score. The system demonstrates practical implementation of essential network programming concepts.
- Implementation:
QuizServer.java,QuizClient.java - Description: Establishes reliable, connection-oriented communication between server and clients
- Usage: Main communication channel for quiz questions and answers
- Implementation:
ClientHandler.java, Thread pool inQuizServer.java - Description: Handles multiple client connections concurrently using separate threads
- Usage: Each client connection runs in its own thread, allowing simultaneous player participation
- Implementation:
QuizService.java, synchronized methods and blocks - Description: Thread-safe management of shared resources (player scores, quiz state)
- Usage: Prevents race conditions when multiple threads update player scores
- Implementation:
UDPBroadcaster.java,UDPResultsListener.java - Description: Connectionless broadcasting of final results to all clients
- Usage: Broadcasts final leaderboard to all clients on the network
- Implementation: Throughout the application
- Description: Bidirectional message exchange using JSON protocol
- Usage: Structured communication for quiz flow, questions, answers, and results
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Quiz Server โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ TCP Socket โ โ Thread Pool โ โ UDP Socket โ โ
โ โ (Port 5000) โ โ (Max 10) โ โ (Port 5001) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโผโโโโโ โโโโโโผโโโโโ โโโโโโผโโโโโ
โ Client 1โ โ Client 2โ โ Client 3โ
โ(TCP+UDP)โ โ(TCP+UDP)โ โ(TCP+UDP)โ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
- Java: JDK 17 or higher
- Maven: 3.6 or higher
- IDE: IntelliJ IDEA, Eclipse, or VS Code (optional)
-
Clone or Download the Project
cd "e:\MCQ spring"
-
Build the Project
mvn clean install
-
Start the Server
mvn spring-boot:run
The server will start on:
- HTTP Server: http://localhost:8080
- TCP Socket: Port 5000
- UDP Socket: Port 5001
-
Access Web Interface
- Open browser: http://localhost:8080
- View server status and leaderboard
-
Run Client Application (Open multiple terminals for multiple clients)
java -cp target/online-quiz-system-1.0.0.jar com.quiz.client.QuizClient
- Start the Server: Run the Spring Boot application
- Connect Clients: Run the client application (minimum 2 clients required)
- Enter Name: Each client enters their player name
- Wait for Players: Server waits for at least 2 players before starting
- Answer Questions: Players answer 5 multiple-choice questions
- View Results: Final results are displayed via TCP and broadcast via UDP
MCQ spring/
โโโ src/
โ โโโ main/
โ โโโ java/com/quiz/
โ โ โโโ QuizApplication.java # Spring Boot main class
โ โ โโโ model/
โ โ โ โโโ Question.java # Question model
โ โ โ โโโ Player.java # Player model
โ โ โ โโโ QuizMessage.java # Message protocol
โ โ โโโ service/
โ โ โ โโโ QuizService.java # Quiz logic & synchronization
โ โ โโโ server/
โ โ โ โโโ QuizServer.java # TCP server & multithreading
โ โ โ โโโ ClientHandler.java # Thread per client
โ โ โ โโโ UDPBroadcaster.java # UDP broadcasting
โ โ โโโ client/
โ โ โ โโโ QuizClient.java # Client application
โ โ โ โโโ UDPResultsListener.java # UDP receiver
โ โ โโโ controller/
โ โ โโโ QuizController.java # REST API endpoints
โ โโโ resources/
โ โโโ application.properties # Configuration
โ โโโ static/
โ โโโ index.html # Web UI
โ โโโ styles.css # Styling
โ โโโ script.js # Frontend logic
โโโ pom.xml # Maven configuration
โโโ README.md # This file
Edit src/main/resources/application.properties:
# Server Configuration
server.port=8080
quiz.server.tcp.port=5000
quiz.server.udp.port=5001
quiz.server.max.clients=10- โ Accept multiple client connections (TCP)
- โ Handle clients concurrently (Multithreading)
- โ Manage quiz flow and questions
- โ Track player scores safely (Synchronization)
- โ Broadcast final results (UDP)
- โ Web-based monitoring dashboard
- โ REST API for status and leaderboard
- โ Connect to server via TCP socket
- โ Real-time question receiving
- โ Interactive answer submission
- โ Score tracking
- โ UDP broadcast reception
- โ Console-based UI
- Start server
- Connect 2 clients
- Both clients enter names
- Server starts quiz automatically
- Clients answer all questions
- View final results
- Start server
- Connect 5+ clients simultaneously
- Verify all clients receive questions
- Check synchronization of scores
- Confirm UDP broadcast reaches all
- TCP: Monitor connection establishment and data transfer
- Multithreading: Check server logs for thread creation
- Synchronization: Verify score consistency across threads
- UDP: Confirm broadcast reception on all clients
- Client-Server: Observe bidirectional message flow
| Member | Role | Concept | Implementation |
|---|---|---|---|
| Member 1 | Server Developer | TCP Socket | QuizServer.java |
| Member 2 | Manager | Multithreading | ClientHandler.java |
| Member 3 | Client Developer | Client-Server | QuizClient.java |
| Member 4 | Score Manager | Synchronization | QuizService.java |
| Member 5 | Broadcaster | UDP Datagram | UDPBroadcaster.java |
===========================================
Quiz Server Started on Port: 5000
Waiting for clients to connect...
===========================================
Player joined: Alice (uuid-1234)
Player joined: Bob (uuid-5678)
Starting quiz with 2 players
===========================================
Quiz Started!
===========================================
Question 1: What is 2 + 2?
--- Current Scores ---
1. Alice - 10 points
2. Bob - 0 points
...
===========================================
ONLINE QUIZ SYSTEM - CLIENT
===========================================
Connected to Quiz Server!
Enter your name: Alice
Waiting for other players... (2 players connected)
===========================================
Question 1 of 5
===========================================
What is 2 + 2?
1. 3
2. 4
3. 5
4. 6
Your answer (1-4): 2
Correct!
Your current score: 10 points
- Check if ports 5000, 5001, 8080 are available
- Verify Java 17+ is installed
- Run
mvn clean installagain
- Ensure server is running
- Check firewall settings
- Verify SERVER_HOST and SERVER_PORT in QuizClient.java
- Check network configuration
- Verify UDP port 5001 is open
- Try using localhost for testing
This is an educational project. For production use, consider:
- Input validation and sanitization
- Authentication and authorization
- Encrypted communication (TLS/SSL)
- Rate limiting
- SQL injection prevention (if using database)
This project is created for educational purposes as part of a Network Programming course.
This is a group project. All team members contribute to different modules as per their assigned roles.
For questions or issues, please contact your course instructor or teaching assistant.
Built with โค๏ธ for Network Programming Module