title: javascript catch comet socket disconnect
body: <p>So I have implemented comet sockets on my server, and am able to push data to the browser fine. But what I would like to do is catch in javascript/jquery when the comet server drops out. </p>
  
  <p>I have my iframe:</p>
  
  <pre><code>&lt;div id="iframeDiv" style="visibility:hidden; height:0px"&gt;
      &lt;iframe id="comet" src="/messageSocket?-3711886712169888393"&gt;&lt;/iframe&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and i have my javascript to handle the new message:</p>
  
  <pre><code>// Comet Server Processes actions
  var messageReceived = function(message) {
  var commandType = message[1];
  switch (commandType) {
      case "1":
          processActionData(message);
          break;
      ...
      default:
          break;
  }
  
  }
  </code></pre>
  
  <p>but for example lets say the connection drops for whatever reason? How can I bring it back up? For example if the local server hosting the website shuts down and starts back up again I would like on the client to catch a timeout? And then reload the page. How do I do this? Do I need to create a loops that makes an ajax ping requests to determine if the connection is still alive? Is there a better way to just catch when the comet socket dies?</p>