README.md
md1 kBIn IN441- Code.zip
Exercise 1
Write a Java program using UDP sockets to implement a "Multi-Client Game Server" that performs simple text operations and score tracking. The server accepts multiple clients, processes their commands, and maintains individual scores based on correct responses.
Server Side
- Listens on a specified UDP port for messages from multiple clients.
- When a new client connects (detected by a
"JOIN:username"message), the server:- Assigns a unique player ID based on IP and port.
- Initializes their score to 0.
- Sends a welcome message and a random challenge (e.g., "Convert hello to uppercase").
- Processes commands from clients:
ANSWER:<text>: Validates the client's answer.- If correct, increases their score and sends
"Correct! Your score is X". - If incorrect, sends
"Wrong answer, try again.".
- If correct, increases their score and sends
SCORE: Sends the current score to the client.NEXT: Sends a new random challenge (e.g., "Reverse the string world").EXIT: Removes the client from the active players list and sends a goodbye message.
Client Side
- Prompts the user for a username and sends
"JOIN: username"to the server. - Receives a welcome message and a challenge (e.g., "Convert hello to uppercase").
- The user can:
- Send
ANSWER:<text>to respond. - Send
SCOREto check their score. - Send
NEXTto get a new challenge. - Send
EXITto leave the game.
- Send