A simple real-time multiplayer chess game built using WebSockets .
Players can create a room, share a room code with a friend, and play a live chess game with instant move updates.
output.mp4
The primary goal of this project is to understand and implement WebSockets in a real-world scenario.
Chess is used as the medium to explore:
- real-time client–server communication
- multi-client synchronization
- room-based message isolation
- socket lifecycle management
This project focuses on real-time systems, not on building a production-scale chess platform.
- Bi-directional communication using Socket.IO
- Moves are transmitted instantly between players
- One player creates a room and receives a unique room code
- Another player joins using the same code
- Each room represents a single isolated game
- Only two players can participate in a game
- Rooms are isolated to prevent cross-game interference
- Once both players join, the server randomly assigns:
- White to one player
- Black to the other
- Game rules handled using chess.js
- Chessboard rendered using react-chessboard
- Moves are mirrored in real time across both clients
- Socket connection initialized on component mount
- Event listeners registered once
- Proper cleanup and disconnection on unmount
- Client ↔ Server communication handled via custom socket events
- Clear separation between connection, game start, and move updates
This project demonstrates practical understanding of:
- WebSocket fundamentals
- Socket.IO rooms
- Real-time event handling
- Multi-client coordination
- Client–server communication flow
- Preventing common socket issues (duplicate listeners, leaks)
- React
- react-chessboard
- socket.io-client
- Node.js
- Socket.IO
- chess.js
MONGO_URI=""
PORT="3000"
SALT=10
JWT_SECRET_KEY="mysecretkey"
CLIENT_URL=""
VITE_BACKEND_URL=""
- Player creates a room and gets a room code
- Second player joins using the same code
- Server assigns colors once both players are present
- Moves are sent from one client to the server
- Server broadcasts the move to the opponent in real time
- Reconnection support
- Persistent game state
- Server-side move validation
- User identity and authentication
- Spectator mode