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