This project is a two-player trivia game implemented in C using TCP sockets. One program runs as a server and coordinates the game, while two clients connect, receive trivia questions, submit answers, and compete for the highest score.
The server enforces basic synchronization by waiting for both players to answer each question before updating scores and advancing the game. All trivia content is read from a file, making the game data-driven and easy to extend without modifying source code.
The project is intentionally terminal-based and lightweight, focusing on core systems programming concepts such as socket communication, blocking I/O, and client–server coordination.
server.c
Implements the trivia server. Sets up a TCP socket, accepts exactly two client connections, reads questions from a file, receives answers from both players, checks correctness, and maintains player scores.
client.c
Implements the trivia client. Connects to the server, sends a player name, displays questions received from the server, submits answers, and prints score updates.
questions.txt
Primary trivia question file used by the server.
questionss.txt
Alternate trivia question file using the same format.
Makefile
Builds the server and client programs.
Requirements:
- A Unix-like environment (macOS or Linux)
- gcc installed
Steps:
git clone https://github.com/SutejUpadhyaya/Client-Server-Trivia.git
cd Client-Server-Trivia
make
After building, two executables will be created:
server
client
Open a terminal and run:
./server
The server will start listening and wait until two players connect.
Open two separate terminals (or use two different machines on the same network) and run:
./client
Each client will:
- Prompt for a player name
- Receive trivia questions from the server
- Submit answers
- Receive score updates after both players answer
The game continues until the question file is exhausted.
To run the game across different computers:
- Start the server on one machine.
- Update the server IP address in client.c if needed.
- Build the project on each machine using make.
- Run the server on one machine and the clients on two machines connected to the same network.
Each trivia question consists of four parts:
- One line containing the question
- One line containing three possible answers separated by spaces
- One line containing the correct answer (must exactly match one of the options)
- A blank line separating questions
Example:
What is the capital of France?
Berlin Madrid Paris
Paris