This project implements a distributed Tic Tac Toe game using Java RMI (Remote Method Invocation). Players can connect to a central server, join game sessions, and play against opponents in real-time with automatic matchmaking.
Note
A command-line interface is available in /cli for testing purposes. The GUI version is recommended for end-users.
- Distributed Architecture: Server handles game logic, clients manage UI
- Dynamic Session Management: Auto-scales game sessions as players connect
- Rematch System: Players can restart games after completion
- Heartbeat Monitoring: Detects disconnected players automatically
- Modern GUI: Clean interface with game board, status updates, and controls
- Connection Security: Custom security manager for RMI communication
| Class | Purpose | Key Features |
|---|---|---|
| ServerMain | Server entry point | Starts RMI registry, registers primary service |
| TicTacToeServer | Session manager | Creates/destroys game sessions, manages player allocation |
| TicTacToeServiceImpl | Game logic core | Move validation, win detection, player management |
| ClientMain | Client entry point | Launches game GUI |
| TicTacToeGUI | Player interface | Game board, status display, input handling |
| TicTacToeClient | Client logic | Server communication, game state management |
| PlayerCallbackImpl | Server→client comms | Real-time updates, heartbeat monitoring |
| MySecurityManager | Security config | Enables RMI connections without strict policy files |
| GameConstants | Shared config | Board size, player symbols, game rules |
- Java JDK 17+
- Network connectivity between machines
- RMI ports open (1099 + 1100-1106 by default)
javac -d bin src/server/*.java src/client/*.java src/common/*.java src/security/*.javajava -cp bin -Djava.rmi.server.codebase=file:bin/ security.MySecurityManager server.ServerMain 192.168.1.10Note
Replace 192.168.1.10 with server's actual IP
java -cp bin -Djava.rmi.server.codebase=file:bin/ security.MySecurityManager client.ClientMainNote
Run on player machines, enter server IP when prompted
Players connect via the GUI by entering server details:
- Server IP (e.g.,
localhostfor local testing) - Client IP (auto-detected or manually entered)
- Invalid IP formats trigger validation warnings
- Duplicate player names are rejected
- Server automatically pairs available players
- New game sessions are created on-demand
- Players see "Waiting for opponent" status until matched
Players take turns making moves on the board:
Features:
- Turn indication ("YOUR TURN" vs "Opponent's turn")
- Visual board updates after each move
- Real-time move validation (prevents invalid placements)
Game automatically detects end conditions:
- Win: 3-in-a-row patterns
- Draw: Full board with no winner
Error Recovery:
- Network drops trigger automatic reconnection attempts
- Missing heartbeats mark players as "disconnected"
- Session timeouts after 30 seconds of inactivity
After game completion:
- Both players get rematch prompts
- New game starts if both choose "Play Again"
- Session dissolves if either player quits
Players can quit anytime via:
- "Quit Game" button during gameplay
- Window close (X) button (NOT ON WINDOWS)
- Console interrupt (Ctrl+C) for CLI clients
Termination Sequence:
- Client sends disconnect notification
- Server frees game resources
- Opponent receives "Player left" notification
- Session automatically closes after 60 seconds
| Parameter | Location | Description |
|---|---|---|
| MAX_SESSIONS | TicTacToeServer.java | Max concurrent game sessions |
| portBase | TicTacToeServer.java | Starting port for game sessions |
| sun.rmi.transport.* | TicTacToeClient.java | Network timeout settings |
| Color constants | TicTacToeGUI.java | UI color scheme |
- Observer Pattern: Callbacks for game state updates
- Singleton Pattern: Central server instance
- Factory Pattern: Dynamic session creation
- Asynchronous Processing: Non-blocking game operations
- Connection Issues: Verify IPs match server's network interface
- Port Conflicts: Change portBase in TicTacToeServer.java
- Session Limits: Increase MAX_SESSIONS if needed
- Timeout Errors: Adjust sun.rmi.transport.* properties



