views:

58

answers:

2

Hi, I am trying to create real-time and collaborative application like - google wave for example. When user1 writes something at the same time it shows on user2 screens.

I started a little research,and found some ways to this with Ajax -

1.every X seconds send request to the server and to check what is "happening"

2.timeout - long request ,Problem - I saw i can do this only with IE8

there are other options?what is the best way to this?
And with way number 2,this true I can do this only with IE8?

Yosy

A: 

The whole point of AJAX is that the server can wait for notifications from each clients, and notify all the other clients when something happens. There's no need for polling. Look up keywords like comet, and bayeux. Dojo has a good implementation.

PanCrit
I searched for comet,And saw that peoples are doing the 2 I gave.
Yosy
Here are some references: http://cometdaily.com/2008/10/14/private-messages-with-cometd-chat/http://simonwillison.net/2007/Dec/5/comet/http://www.ibm.com/developerworks/web/library/j-jettydwr/index.html
PanCrit
A: 

I'm not sure what you are referring to in 2, but if I were going to implement something like this, I'd do what you explain in 1. Basically your server will be keeping track of the conversation, and the clients will constantly ask for updates.

Another possible option would be flash, but I don't know much about that other than it would be capable, so your on your own for researching that.

Some notes on keeping things running quickly in option 1:

  1. Remember you only have 2 "ajax" calls to work with on the client side (you can only have 2 calls out at once). So keep track of the calls that are out. Make use of abort() if a call takes too long or its response is not going to be valid anymore.

  2. Get the most out of your calls, if you need to send text to the server, use the response to get an update on the current "conversation".

aepheus
Ok,options 2 - xhr.timeout = 1000;xhr.ontimeout = function(){ alert("Request did not return in a second");};// from -JavaScript for Web Developers,2nd Editionand If I used option 1 , that means I will need to do this with interval.Right?
Yosy
Right, you'd use an interval.
aepheus