I am exploring the use of Comet for a project I am working on.
I tried creating a test application first using Tomcat6 and CometProcessor API and then with Jetty7 Continuations.
The application is kind of working on both but I am having some issues with the actual display of messages.
I used the technique of creating an XMLHttpRequest Connection and keeping it open all the time so the server can continuously push data to all the clients connected whenever it is available.
My client side code is something similar to this:
function fn(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState==3){
document.getElementById('dv').innerHTML =(xhr.responseText);
}
if (xhr.readyState==4){
alert ('done');
}
}
xhr.open("GET", "First", true);
xhr.send(null);
}
I found this thing of using readyState 3 somewhere online.
I am facing 2 problems currently:
In Firefox this code works perfectly. But if I open a new tab or even a new browser window, it does not make a new connection to the server and nothing shows up on the new tab or window, only the first tab/window gets the display. I used wireshark to check this and its shows only 1 connection even after the 2nd tab is opened. I am unable to understand why this would happen. I have read about the 2 connection limit, but here there is only one connection.
Secondly in Chrome, the above code does not work, and the callback is not invoked for readystate of 3, only when the connection is closed by the server i get the output.
I would also like to ask which is the best way/framework for doing Comet with Java. I am currently using jQuery on the client side.
Any suggestions would be greatly appreciated!! Thanks