Game interaction between two clients ...

Giganews Newsgroups
Subject: Game interaction between two clients ...
Posted by:  Chuck Anderson (cycletourist@invalid.invalid)
Date: Tue, 24 Mar 2009

I am making a web application that allows two (or more) people (at
different locations) to play a simple game of cards.  I'm using
JavaScript (DOM and and XMLHttpRequest) to manipulate the cards on the
client page, and Php and MySQL server side to keep track of the game -
the cards and players - on the server.  What I'm trying to figure out is
the best way to "tell" each player when it is their turn ... when the
other person has finished playing their cards - and update their page to
enable them to take their turn.

The simplest way would be to poll the server using JavaScript every
second or two, but I'm wondering if there is a better  - more efficient
way.  I searched Google with "push page" and it seems there really is no
such thing (... or is there?).

I saw something called long polling but it appeared to merely put the
loop on the server.  Although I didn't really understand completely how
it worked, my impression is that the client opens a connection to the
server (with Ajax like functionality) and then waits for the server to
respond.  The trade off seems to be either; having the server sit in a
loop checking the database for when the other player is finished and
then responding to the client, or making the client sit in a loop
interrogating the server.

I'm looking for suggestions on the best way to accomplish this (quick)
communication between two separate clients via the server.  Any suggestions?

Chuck Anderson • Boulder, CO
Turn Off, Tune Out, Drop In