GithubHelp home page GithubHelp logo

multiplayer_tic-tac-toe's Introduction

Multiplayer Tic-Tac-Toe

A multiplayer Tic-Tac-Toe game using C socket programming in which a Server creates the game in Local Area Network. The players in LAN can connect to the server using IP address of server provided. The connection to the server will be a client-server approach whereas the players will be playing with each other in a Peer-to-Peer fashion.

Server Side (server.c) :

Server listens for incoming connections from players.When a connection arrives, new thread will be created. To handle this connection maintaining the concurrency of the server, each connection is opened in a new socket. New socket descriptor is created which will be passed to our thread. When players are connected, they can query to join, leave, list and challenge other players. Program store a list of all players that have joined which is protected by a mutex to prevent race conditions from taking place between threads.

Client Side (client.c) :

Client/Peer program opens a connection with the server program on launch. Creates a new thread to handle communication with the server. Binds to a port and starts listening for incoming connections. Player can query the server to join, leave, list or challenge other players. If ‘invite {playername}’ query is entered, then the server returns the IP of this player from the hashmap. The client program closes the thread with the server but maintains the connection and uses the supplied IP address to open a direct connection with the peer associated with this IP in a new thread. This connection is accepted on the port that invited player is listening to. On the other side, the invited player can refuse or accept to play a game. The players can keep playing until one of them declines.When the game finishes, the inviting player closes his thread and socket. It then recreates the thread to start querying the server again.The invited player on the other hand goes back to listening for other connections and recreates its server thread as well.

Hash Table (strmap) :

ANSI C hash table for strings is used to save the list of active clients connected to the server. For this strmap which is an open source is used with some modifications as needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.