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