-1

im new to networking and currently im making a multiplayer game via java socket. so i want to ask a simple question. the game will be like this :

  • the game needs 3 player to start
  • the tile is 3x3

  • if all the player already join the server the game will be started

  • each player will be given a turn to clicking the button that contain image , example : player a clicking button 1 , and then the turn will be given to player b , player b clicking button 2 and then the turn will be given to player c , etc

MY QUESTION IS :

  • how do i give a timer for each player turn? what i want is if the player doesnt clicking/idle for a period time the turn will be throw to the next player. am i need to manage it in my server or client? and how?

  • how to handle a player that disconnected? if the player disconnect i want the turn will automatically given to the next player.

2 Answers2

0

In theory, both the client and the server could handle the timer. If the server does it, it starts the timer after giving the turn to player X, and after the timer ran out, it stops the turn of player X. If you do it on client side, the client could just start the timer after receiving the turn, and then send a specific response to the server if the user did not provide input.

Now what is better? Of course the server solution. If your client disconnects, the server would keep waiting for an answer from your client, which might not even come back anymore. So you are better off doing this on server side.

PKlumpp
  • 4,913
  • 8
  • 36
  • 64
0

As a client disconnect is a likely cause of such a time-out, you would most likely need to implement it on the server. You can do this for instance by creating a Timer, see e.g. here. Once the timer thread ends, a message could be send to the client that did not respond within time. When doing so, you should take into account that the client is unreachable, of course

DennisV
  • 128
  • 1
  • 10