Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Readme.md

Introduction

Client-Server Connection

An example Android application demonstrating client-server interaction. The BleServerManager is responsible to open the Gatt server and initializing services. The server will advertise the services through GATT server using a randomly generated service UUID and make Gatt services available to remote scanning devices.

The client, on the other hand, will start scanning for an advertising device with the same service UUID and connect with the one it discovers first. Once the connection is established, both the client and the server start interacting with each other. A BleManager instance is responsible for connecting and communicating with a peripheral device.

Data transmission between client and server

The transmission of the data between the client and server is performed using the Protocol Buffer (Protobuf). Protobuf is more efficient than text-based formats (such as JSON) in terms of speed and code size, making it more suitable for use in mobile environments. Wire Compiler has been utilized to compile the Protobuf in this project.

Data transmission between client and server is depicted in the diagram.

sequenceDiagram
    Server-->Client: connect
    loop Connection
        Client->>Server: user name
        Note left of Server: Checks for invalid name
        Note left of Server: if valid, saves username
        Server->>Client: All joined users' name
        Note right of Client: Displays all joined username
        Note right of Client: Waits for server to start game
        Note left of Server: Start Game
        Server->>Client: Question
        Client->>Server: Selected answer id
        Note left of Server: Checks answer. If correct, updates score
        Server->>Client: Correct answer id
        Note right of Client: Wait for next question
        Server->>Client: Next Question
        Note over Server,Client: Process continues until game over
        Server->>Client: Game Over
        Server->>Client: Result
    end
Loading

About the game

This is a simple quiz game that could be played by multiple players. It includes a server that will host the game and one or more clients. Each participant will be given a question and multiple answers from which they must choose one. A timer will appear at the top of the screen, allowing the user to choose the correct answer within a given time limit. Only one response per question will be allowed. Once the timer is off, the right answer will be highlighted on each player's screen. If the user's selection is correct, it will be highlighted in green; otherwise, it will be highlighted in red. At the end of the game, all players' scores will be distributed. A total of ten questions collected from an open source Trivia API will be presented.

startScreen userNameDialog waitingServer startGame questionContent nextButton gameOver result

Requirements

Required permissions

On Android 6 - 11, it will ask for Location Permission and Location services. This permission is required on Android in order to obtain Bluetooth LE scan and advertise results. This permission is not required from Android 12 onwards, where new Bluetooth permissions were introduced. The BLUETOOTH_SCAN permission can now be requested with usesPermissionFlags="neverForLocation" parameter, which excludes location related data from the scan results, making requesting location not needed anymore.

Furthermore, internet access permission is needed to retrieve the question data from the Trivia API.