This project is a real-time, multiplayer networked game developed for the Network Programming module. It demonstrates high-performance synchronization of game states across multiple hosts using a robust Client-Server architecture.
The server utilizes a dedicated ClientHandler thread for every connected user. This ensures:
- Non-blocking Communication: The server can process inputs from Player A without making Player B wait.
- High Responsiveness: Actions are processed in parallel, maintaining a "real-time" feel.
We utilize Java's ServerSocket and Socket libraries.
- Reliability: Uses the TCP protocol to ensure no "move" packets are lost or arrive out of order.
- Stream-Based: Data is transmitted efficiently through
PrintWriterandBufferedReader.
The game uses a lightweight, custom messaging protocol to minimize latency:
MOVE:dx,dy→ Client informs server of movement intent.UPDATE:ID:X:Y→ Server broadcasts the new "Source of Truth" to all clients.
A responsive front-end built with Java Swing that separates concerns:
- Event Thread: Handles key presses and UI rendering.
- Network Thread: Runs in the background to listen for server updates without "freezing" the window.
| Requirement | Implementation Status |
|---|---|
| Unique Title | Multiplayer Square Tag |
| Thread Usage | Implemented on both Server (Client Handlers) and Client (Network Listener) |
| Multi-host | Tested across multiple devices using local IPv4 addressing |
| No Libraries | Built using 100% standard Java SE libraries (java.net, java.io, java.awt) |
- Java JDK 8 or higher installed.
- Start the Server:
Run
GameServer.java. The console will display:Game Server started on port 5000. - Launch Clients:
Run
GameClient.javaon one or more machines.- Note: For multi-host play, replace "localhost" in the code with the Server's IPv4 address (e.g., 192.168.8.x).
- Controls: Use the Arrow Keys to move your square.