www.webdeveloper.com
Results 1 to 2 of 2

Thread: Comet reliability problem

  1. #1
    Join Date
    Oct 2009
    Posts
    1

    Question Comet reliability problem

    Hi, I have a simple piece of IE comet javascript codes as shown below. The script works and I can see the streaming messages on IE 6/7/8. However, after it runs for awhile, the stream stops. In my IE8 test, after 4 hour; users reported the problem at 30 minutes in IE6/7. In IE 8, I observed that the whole browser hung and hijacked the CPU. The codes look pretty standard comet codes to me. The same test on firefox (JS codes not shown) can run for over 8 hours w/o any problem.

    Questions:

    Has this way (using iframe) of doing comet known to be unreliable after awhile or is there anything wrong with this piece of codes?

    I also tried to implement comet using Msie.XMLHttp, following some examples I seen on the web, but it does not seem to work. Is it possible? where can I find a correct example or article on this?

    Thanks!


    Code:
    // the only option used is 'debug' w/ the value of the output element
    jQuery.cometStart = function(url, options, callback) {
    
       if(jQuery.isFunction(options)) {
          callback = options;
       }
       
       jQuery.cometSettings.pos = 0;
       
       if(jQuery.browser.msie) {
          
          var doc = new ActiveXObject('htmlfile');
          doc.open();
          doc.write('<html>');
          doc.write('<script>document.domain = \'' + document.domain + '\'');
          doc.write('</html>');
          doc.close();
          var div = doc.createElement('DIV');
          doc.appendChild(div);
          
          div.innerHTML = '<iframe name=\'ifr\' src=\'' + url + '\'></iframe>';
          jQuery.cometSettings.active = true;
          
          if(! jQuery.cometSettings.interval) {
             jQuery.cometSettings.interval = setInterval( function() {
                
                var xmlhttp = doc.frames['ifr'].document;
    
                if(typeof xmlhttp != 'undefined' && typeof xmlhttp.readyState != 'undefined' && xmlhttp.readyState == 'complete') {
                   clearInterval(jQuery.cometSettings.interval);
                   jQuery.cometSettings.interval = false;
             
                   if(jQuery.cometSettings.active)   {
                      jQuery.cometStart(url, options, callback);
                   }
                }
                
                var data; 
                try {
                   data = xmlhttp.firstChild.innerHTML;
                }
                catch(error) {
                   return false;
                }
                
                data = data.substr(jQuery.cometSettings.pos);
    
                if(data.indexOf('<SCRIPT>') < 0) {
                   return false;
                }
    
                var start = data.indexOf('<SCRIPT>') + 8;
                var stop = data.indexOf('</SCRIPT>') - start;
                data = data.substr(start, stop);
    
                debug(data);
    
                try {
                   eval('data = ' + data);
                }
                catch(error) {
                }
    
                if (callback) callback(data);
             
                jQuery.cometSettings.pos = jQuery.cometSettings.pos + start + 8 + stop - 1;
          
                 if(!jQuery.cometSettings.active) {
                    try { xmlhttp.abort(); } catch (e) {}
                    return(false);
                 }
             }, 250 );
          }
       }
       else if(jQuery.browser.mozilla) {
           // codes omitted
       }
       else {
          alert('Unsupport browser. Please use Microsoft Explorer 7+ or Mozzila Firefox 3+');
       }
    
       function debug(data) {
          
          if(typeof(options) == 'object' && jQuery(options.debug)) {
             jQuery(options.debug).prepend(data + '\n\n');
          }
       }
    };

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    ie does have a history of memory leaks.
    you might try nulling the vars after you are done with them.
    creating four windows and running eval and catches can't be more most efficient use of resources. Frankly i'm surprised it makes it half hour at that rate.


    i have had better luck with tricking script tags than with iframes, might be worth a shot.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles