kamputty
03-31-2009, 10:39 PM
Hi all!
I'm working on my ajax stuff, and I'm having an interesting issue.
The setup:
#1. I have a server running a servlet on port 8181
#2. I have Safari loading my test page
#3. this Test page creates a long term ajax connection to the server
#4. When the server "sends" data to the client on this line, I can "see" the data on wireshark, and on the browser if I call the server directly. BUT, in my javascript, I do not see anything! It does come back to the callback, but there is no data!!!
Here is the returning json
/*<event-start>*/{"created":1238535212238,"parent-event-id":"1","parent-event-type":"1000","parent-event-status":"OK","type":4,"id":1}/*<event-end>*/
The "<event-start>" and "<event-end>" are my delimiters for events.
Said that, is there anything special on the javascript side?
Here is now I create the ajax connection
/*
This method returns the correct http request pipe
*/
createXMLHttpRequest=function()
{
// Lets create the correct type. For the actual hardware, we will not need the Microsoft versions
try { return new XMLHttpRequest();} catch(e)
{
}
try { return new ActiveXObject("Msxml2.XMLHTTP");} catch(e)
{
}
try { return new ActiveXObject("Microsoft.XMLHTTP");} catch(e)
{
}
alert("XMLHttpRequest not supported");
return null;
}
// This method connects to the backend
this.makeLTEPConnection=function(id, func, url)
{
httpLTEP=createXMLHttpRequest();
connectionCounter=0;
connectionErrorCounter=0;
buffer="";
httpLTEP.open("GET", url, true);
httpLTEP.onreadystatechange = func;
httpLTEP.overrideMimeType('text/plain; charset=x-user-defined'); // we need this else the system will parse the instream as html
httpLTEP.send(null);
return;
};
and here is the callback fun
// This method receives the event message
this.receivedEventMessage=function()
{
try
{
var eventResults=extractMPEvents(httpLTEP.responseText);
// skip if we do now have any results
if(eventResults===undefined)
{
return false;
}
.
.
.
Now, I was testing this using not a servlet, but a simple cgi that would emulate the servlet
#!/usr/bin/perl
$| = 1;
for($i=0;$i<4;$i++)
{
print "Content-type: text/plain\r\n\r\n";
$value=$i % 4;
print '<event-start>';
print "{\"event\" :";
print " {";
print " \"id\" : \"$i\",";
print " \"type\" : \"$value\",";
print " \"msg\" : \"Kam Was Here!\",";
print " \"url\" : \"http://10.5.251.66/demo/screensaver/html/screensaver.html\",";
print " }";
print "}";
print '<event-end>';
#sleep between 0-1 seconds
select(undef,undef,undef, rand());
}
Use the above script works. When I use the servlet, it sends the data, BUT I do not "see" any data...
Thoughts?
~Kam (^8*
I'm working on my ajax stuff, and I'm having an interesting issue.
The setup:
#1. I have a server running a servlet on port 8181
#2. I have Safari loading my test page
#3. this Test page creates a long term ajax connection to the server
#4. When the server "sends" data to the client on this line, I can "see" the data on wireshark, and on the browser if I call the server directly. BUT, in my javascript, I do not see anything! It does come back to the callback, but there is no data!!!
Here is the returning json
/*<event-start>*/{"created":1238535212238,"parent-event-id":"1","parent-event-type":"1000","parent-event-status":"OK","type":4,"id":1}/*<event-end>*/
The "<event-start>" and "<event-end>" are my delimiters for events.
Said that, is there anything special on the javascript side?
Here is now I create the ajax connection
/*
This method returns the correct http request pipe
*/
createXMLHttpRequest=function()
{
// Lets create the correct type. For the actual hardware, we will not need the Microsoft versions
try { return new XMLHttpRequest();} catch(e)
{
}
try { return new ActiveXObject("Msxml2.XMLHTTP");} catch(e)
{
}
try { return new ActiveXObject("Microsoft.XMLHTTP");} catch(e)
{
}
alert("XMLHttpRequest not supported");
return null;
}
// This method connects to the backend
this.makeLTEPConnection=function(id, func, url)
{
httpLTEP=createXMLHttpRequest();
connectionCounter=0;
connectionErrorCounter=0;
buffer="";
httpLTEP.open("GET", url, true);
httpLTEP.onreadystatechange = func;
httpLTEP.overrideMimeType('text/plain; charset=x-user-defined'); // we need this else the system will parse the instream as html
httpLTEP.send(null);
return;
};
and here is the callback fun
// This method receives the event message
this.receivedEventMessage=function()
{
try
{
var eventResults=extractMPEvents(httpLTEP.responseText);
// skip if we do now have any results
if(eventResults===undefined)
{
return false;
}
.
.
.
Now, I was testing this using not a servlet, but a simple cgi that would emulate the servlet
#!/usr/bin/perl
$| = 1;
for($i=0;$i<4;$i++)
{
print "Content-type: text/plain\r\n\r\n";
$value=$i % 4;
print '<event-start>';
print "{\"event\" :";
print " {";
print " \"id\" : \"$i\",";
print " \"type\" : \"$value\",";
print " \"msg\" : \"Kam Was Here!\",";
print " \"url\" : \"http://10.5.251.66/demo/screensaver/html/screensaver.html\",";
print " }";
print "}";
print '<event-end>';
#sleep between 0-1 seconds
select(undef,undef,undef, rand());
}
Use the above script works. When I use the servlet, it sends the data, BUT I do not "see" any data...
Thoughts?
~Kam (^8*