I have been working on a small two player web based game. I am not sure how to sync up player's moves. for ex., if player1 & player2 are playing the game, how do I communicate the moves of each player between them. I am of the opinion that I have to use some event to update the server after a move occurs at one end, but I am not sure how the other player(browser client) will get the data as and when an update occurs, (again an event there?) ?
As a more practical ex., if two play a chess game, how do I reflect the move made by one on the opponent's screen, so that the opponent will make move according to the new chess board configuration..
@ David, thanks first up. Now, even If I am doing it in AJAX, I need to send back some info to the server so that the client @ the other end can pick it up. So I just want to know how do I get it going.
I dont know Ajax but as Dave said above Flash is another option. And I also think it is better as it will also help you with GUI for the game. Also I think that you will need periodic page refresh or a similar mechanism to get updated positions.
Originally posted by R Sriram: @ David, thanks first up. Now, even If I am doing it in AJAX, I need to send back some info to the server so that the client @ the other end can pick it up. So I just want to know how do I get it going.
The AJAX request from a player sends info to the server letting it know about the player's move.
Now it is the server's turn to inform the second player of information. This can be done a few ways: 1) There is a regular page refresh either with a meta refresh tag, or a javascript timeout. 2) Regularly scheduled AJAX calls poll the the server for information 3) You use a second framework, called Pushlets, to allow the Server to Push content to the Player. See The Pushlets Home Page
With a combination of AJAX and Pushlets you can get a pretty nice event driven web game.
Originally posted by R Sriram: @ David, thanks first up. Now, even If I am doing it in AJAX, I need to send back some info to the server so that the client @ the other end can pick it up. So I just want to know how do I get it going.
@Amit, Name Changed!
First, please try to use real words when posting to the ranch. All those 'at' symbols (@) don't help people who are using language translation software to read your posts.
A two player game is an advanced topic for servlets. If you're not already really strong with both servlets and web development in general, you might want to step back from this goal and work through some simpler projects to strengthen your knowledge of all the necessary technologies before trying something that pushes the boundaries like this one.
Steve, Thanks for your reply. I was just trying to figure if there was something like this(Pushlets)! Ben, I thought the symbol(at-the-rate) meant the same in all languages. Anyways will try to cut down on those.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.