Skip to content

dinujayawkt/Quickzz-with-springboot

Repository files navigation

🎯 Online Quiz System - Multi-Client Real-Time Quiz Game

A comprehensive network programming project demonstrating 5 key Java networking concepts through an interactive quiz application.

📋 Project Overview

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.

🎓 Network Programming Concepts Demonstrated

1. TCP Socket Programming

  • Implementation: QuizServer.java, QuizClient.java
  • Description: Establishes reliable, connection-oriented communication between server and clients
  • Usage: Main communication channel for quiz questions and answers

2. Multithreading

  • Implementation: ClientHandler.java, Thread pool in QuizServer.java
  • Description: Handles multiple client connections concurrently using separate threads
  • Usage: Each client connection runs in its own thread, allowing simultaneous player participation

3. Synchronization

  • 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

4. UDP Broadcasting

  • Implementation: UDPBroadcaster.java, UDPResultsListener.java
  • Description: Connectionless broadcasting of final results to all clients
  • Usage: Broadcasts final leaderboard to all clients on the network

5. Client-Server Communication

  • Implementation: Throughout the application
  • Description: Bidirectional message exchange using JSON protocol
  • Usage: Structured communication for quiz flow, questions, answers, and results

🏗️ Architecture

┌─────────────────────────────────────────────────────────┐
│                    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)│
   └─────────┘      └─────────┘     └─────────┘

🚀 Getting Started

Prerequisites

  • Java: JDK 17 or higher
  • Maven: 3.6 or higher
  • IDE: IntelliJ IDEA, Eclipse, or VS Code (optional)

Installation & Setup

  1. Clone or Download the Project

    cd "e:\MCQ spring"
  2. Build the Project

    mvn clean install
  3. Start the Server

    mvn spring-boot:run

    The server will start on:

  4. Access Web Interface

  5. Run Client Application (Open multiple terminals for multiple clients)

    java -cp target/online-quiz-system-1.0.0.jar com.quiz.client.QuizClient

🎮 How to Play

  1. Start the Server: Run the Spring Boot application
  2. Connect Clients: Run the client application (minimum 2 clients required)
  3. Enter Name: Each client enters their player name
  4. Wait for Players: Server waits for at least 2 players before starting
  5. Answer Questions: Players answer 5 multiple-choice questions
  6. View Results: Final results are displayed via TCP and broadcast via UDP

📁 Project Structure

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

🔧 Configuration

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

📊 Features

Server Features

  • ✅ 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

Client Features

  • ✅ Connect to server via TCP socket
  • ✅ Real-time question receiving
  • ✅ Interactive answer submission
  • ✅ Score tracking
  • ✅ UDP broadcast reception
  • ✅ Console-based UI

🧪 Testing the Application

Test Scenario 1: Basic Quiz Flow

  1. Start server
  2. Connect 2 clients
  3. Both clients enter names
  4. Server starts quiz automatically
  5. Clients answer all questions
  6. View final results

Test Scenario 2: Multiple Clients

  1. Start server
  2. Connect 5+ clients simultaneously
  3. Verify all clients receive questions
  4. Check synchronization of scores
  5. Confirm UDP broadcast reaches all

Test Scenario 3: Network Concepts

  • 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

👥 Group Members & Roles

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

📝 Example Console Output

Server Console:

===========================================
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
...

Client Console:

===========================================
  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

🐛 Troubleshooting

Server won't start

  • Check if ports 5000, 5001, 8080 are available
  • Verify Java 17+ is installed
  • Run mvn clean install again

Client can't connect

  • Ensure server is running
  • Check firewall settings
  • Verify SERVER_HOST and SERVER_PORT in QuizClient.java

UDP broadcast not received

  • Check network configuration
  • Verify UDP port 5001 is open
  • Try using localhost for testing

🔒 Security Notes

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)

📚 Learning Resources

📄 License

This project is created for educational purposes as part of a Network Programming course.

🤝 Contributing

This is a group project. All team members contribute to different modules as per their assigned roles.

📧 Support

For questions or issues, please contact your course instructor or teaching assistant.


Built with ❤️ for Network Programming Module

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors