Turn based web game in PHP - communication issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tommy1999
    New Member
    • Aug 2010
    • 1

    #1

    Turn based web game in PHP - communication issue

    Hi all!

    I am working on a turn based web game in PHP5.

    This is pretty simple game, a kind of board game: two people join a "session" and they play until one of them wins.

    My problem in nutshell:

    * User A and User B play a game.

    * User A finished his turn
    * Request will be sent to the server to perform necessary operations.
    * Now it is time for User B to move..

    But how could I notify User B about this?

    I mean, now the server has to communicate with the other user, the one that is inactive, not the one that initiated the request.

    I know that this could be implemented using some kind of periodic AJAX call that checks whether or not the opponent finished his turn etc, but such a thing generates a huge number of requests.

    Isn't there a better way to solve this?

    I'm thinking of something like this:

    * User A's turn ends
    * Server saves his score
    * Server contacts User B
    * User B's turn gets started.

    Is this possible using PHP? Should I use comet style AJAX? Or is there a better way to do this?

    Any help would be appreciated!

    Thanks in advance!
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    The current web technologies offer no methods for the server to initiate communications with the client. The client has to send a request to the server. HTML5 will remedy this with the WebSockets interface though.

    However, there are ways to trick the browser into maintaining an open connection to the server, allowing the server to send JavaScript triggers to the client. There are several methods you can use. See Comet on Wikipedia. I'd check out the part about "long polling". I suspect it might work out best for your purposes.

    Comment

    • pradeepkr13
      New Member
      • Aug 2010
      • 43

      #3
      How do you see a user when he/she logs out from yahoo messenger?

      Explore the same way.

      Comment

      Working...