Trying to get my way trought Comet with Java servlets, I encountered a big problem: There seems to be no way to use the established connection to the client to send the server additional data from the browser (works in plain java when writing to the inputstream).
Following problem arises for a CometChat application when a Client connects to servlet, receives a form for sending input and a form for presenting server output: Now if the client wants to send some data at this connection, resulting in a READ event at the servlet, how can this be done?
I tried sending GET, HEAD and POST. With HEAD the comet connection is closed afterwards. GET always produces END, BEGIN and POST produces BEGIN, READ.
I tried searching the web, but the only answer I found was: Comet READ events are generating when there is a POST method with a body
How can I achieve this?
I'm using plain Javascript Ajax:
function send(content) {
var text = document.controller.input.value;
params = 'input=' + content;
var ajaxObj = createXMLHttp();
ajaxObj.open('POST', 'CometChat', true);
ajaxObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxObj.setRequestHeader('Content-Length', params.length);
ajaxObj.setRequestHeader('Connection', 'close');
ajaxObj.onreadystatechange = function() {};
ajaxObj.send(params);
}
This produces BEGIN, READ. What headers do I need to set to produce a solely READ event only?
I'm able to 'cheat' this by looking up my connections and reuse response, but on client side, the AJAX request stays in interactive mode (although flushing it on the server) and I'm only able to may 5 requests on FF and 10 requests on IE before the following request is not processed. Also as soon as the first AJAX request is received on the server, I'm get TIMEOUT events, two per request repeating forever.
What's the real way?