Multiplayer TicTacToe game with Sockets & MultiThreading Server can host multiple games each on different Threads
ConnectionListener is in Main thread, when two or more client connects, it calls GameHandler in serepate thread. GameHandler then creates seperate instance of class TicTacToe which takes two Player class object, when game ends, resulting winning/losing/draw state is stored in state class object, which can be then retrived by GameHandler and it calls increase_score method which updates and print global score_board via mutex lock.
Since we are creating seperate objects for different game which are threadsafe so we don't need to worry about mutex in case of client-to-client communication.
But in the case of server-client communication eg updating global scoreboard, we need to use Mutex Locks, so that each thread/client updates score_board one at a time.
- Start the Server
python3 main.py
- Start the client
python3 server.py <PlayerName>
demo.mp4
- Learned creating code with OOPS concepts
- Learned working of multithreading, thread synchronization and use of mutex
- Learned concepts of sockets, and blocking functions