Skip to content

deadshot8086/multiplayer-tictactoe-server-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe

Multiplayer TicTacToe game with Sockets & MultiThreading Server can host multiple games each on different Threads

Internal Working

Model

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.

Model

Use of Mutex

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.

How to Play?

  • Start the Server
python3 main.py

Server

  • Start the client
python3 server.py <PlayerName>

Client

Demo Video

demo.mp4

Learnings

  • Learned creating code with OOPS concepts
  • Learned working of multithreading, thread synchronization and use of mutex
  • Learned concepts of sockets, and blocking functions

References

About

Multiplayer TicTacToe server using sockets and multithreading

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages