1

I'm playing around a bit with the concept of Comet on node.js, but I'm still a bit confused and I'm wondering if anyone here can point me in the right direction.

Think on a game app where client code should ask for it's turn to make a move (for example on a chess app). What I'm thinking here is in use something like this:

When match starts a method on the node server is called to create an element on a matches array with the id of the match and the initial player.

When a player makes a move a method is called to update the current player on the array element referencing this match. This method should fire an event when the change occurs.

Before being able to make any move, client code should call a method on the server that checks if it's the turn of the user and that waits for the changing player event if wasn't it's turn.

I'm not sure if this is a good approach within the event loop, and if it is I don't see how can I make the method to wait until event to return.

Any suggestions?

Bardo
  • 2,470
  • 2
  • 24
  • 42

1 Answers1

0

Node.js and Socket.io are what you need! I have written several games similar to your description. An real-time example: example Another thread: Tutorial on Socket.io

Community
  • 1
  • 1
DanBaker
  • 582
  • 4
  • 13
  • Actually I've turned into socket.io several weeks ago and the game is finished, but thanks anyway. – Bardo Oct 17 '12 at 06:22