views:

37

answers:

2

I want to create an interactive website using aspx and ajax, that there will be an option to create chess game room for example and other players will be able to join.

I have 2 Questions:

  1. I wonder if you have any idea how can I make that after one player clicks on a button and finish his turn, the other player will be able to do a move.

After the first player finish his turn I will change the turn by using the database, but the point is how can I refresh the other player's site so when the other one finish his turn, the turn will come to the second player?

  1. When someone creates a room and than close his browser - I need that room to be closed. Shall I use the Session_OnEnd to close the room he opened?

Thanks!

A: 
  1. The simplest way is probably to do a simple heartbeat/polling on each client to see if it is his/her turn yet. Although, push/comet has been getting easier and easier these days.

  2. If you're already using a polling/heartbeat technique, it would be trivial to close a session after, say, 5 missed heartbeats.

puddingfox
Do you mean creating timer on each client that will check the turn status every second? it's not going to slow down the website because of each one of the new connections to the database every second?and how can I create that timer? can you give me the name of this timer or give me an article about this timer so I will learn how to use it? Thanks
Aviran
Can you also explain what is the push/comet you talked about?
Aviran
push/comet are synonyms for a technology used to replace polling/heartbeat. it is intended to reduce the overhead of polling by creating just one connection for long periods of time rather than a new connection every few seconds http://en.wikipedia.org/wiki/Push_technology
puddingfox
there is also a technique called web sockets that is still being developed -- http://en.wikipedia.org/wiki/Web_Sockets. I don't know of any good tutorials. I have never used web sockets or push myself but I have used polling and it isn't the most efficient or cleanest solution.
puddingfox
+1  A: 

I wonder if you have any idea how can I make that after one player clicks on a button and finish his turn, the other player will be able to do a move.

There are a lot of ways you can do this. If it was me I would have a "moves" database table or something and track whos move it is in there. Then on the page have SetInterval() javascript method that uses an ajax service to look in that "moves" table and determine when it is the users turn.

When someone creates a room and than close his browser - I need that room to be closed. Shall I use the Session_OnEnd to close the room he opened?

You can use Session_OnEnd. As an alternative you could use the ajax method that checks the moves table to see when a user hasn't checked in x minutes, then close their session.

Jason Webb
So I need to use the SetInterval() method every second to check if now its the user's turn in the moves table?because there is a change of the turn duration - when the user finish his turn or until the maximus time that is given to each turn.
Aviran
I would make the delay a little longer than once a second, but yes that is the general idea. If the time needs to vary you can have those rules enforced in the ajax service pretty easily.
Jason Webb
why would you make it a little longer than 1 second (I guess you mean something about 2-3 seconds)?
Aviran
You never know how long the request to the server and back is going to take. Giving it a little longer, say 5 seconds makes it pretty sure that the request will have finished. Really you will need to test it out and see how it works.
Jason Webb