title: sockjs closing after 140 seconds
body: <p>Using node.js and the sockjs github example called 'echo' <a href="https://github.com/sockjs/sockjs-node" rel="nofollow">https://github.com/sockjs/sockjs-node</a>, with no changes, the transport closes in about 130-150 seconds as shown below in the chart. After trying a heartbeat at different rates, does someone with some experience in these things have any ideas why I would need such a low heartbeat rate? Or am I missing something fundamental? Or actually does someone know that this is a normal rate for a production environment?
  Server is 204ms away from the client, tried port 8080 and 442.</p>
  
  <p>The setup:</p>
  
  <pre><code>HTTP, Ubuntu 12.04, Linode VPS
  </code></pre>
  
  <p>Making some small changes to add a heartbeat gives these poor results, indicating a need for about a 5 second heartbeat for Chrome and a 3 second heartbeat for IE. 
  KEY: unlim shows positive result - transport did not close before end of test time 20+ mins. dash shows didn't test</p>
  
  <pre><code>Browser:Chrome  Trans:websocket
  ------------------------------------------
  sec per beat    Closed (Port 8080)      Closed (Port 442)
  30              150 s                       150 s
  25              150 s                       150 s
  15              135 s                       135 s
  12              unlim                       130 s
  10              130 s                       150 s
  8               unlim                       unlim
  6               unlim                       unlim   
  5               unlim                       -
  3               unlim                       -
  
  
  Browser:IE-10  Trans:xhr-stream 
  ------------------------------------------
  sec per beat    Closed (Port 8080)      Closed (Port 442)
  30              180 s                       -
  25              175 s                       -
  15              150 s                       -
  12              156 s                       -
  10              150 s                       -
  8               144 s                       -
  6               90 s                        -
  5               270 s                       256 s
  3               unlim                       unlim
  </code></pre>
  
  <p>Here is the original server code from the sockjs example, changed port only:</p>
  
  <pre><code>var http = require('http');
  var sockjs = require('sockjs');
  var node_static = require('node-static');
  
  // 1. Echo sockjs server
  var sockjs_opts = {sockjs_url: "http://cdn.sockjs.org/sockjs-0.3.min.js"};
  var sockjs_echo = sockjs.createServer(sockjs_opts);
  sockjs_echo.on('connection', function(conn) {
      conn.on('data', function(message) {
          conn.write(message);
      });
  });
  
  // 2. Static files server
  var static_directory = new node_static.Server(__dirname);
  
  // 3. Usual http stuff
  var server = http.createServer();
  server.addListener('request', function(req, res) {
      static_directory.serve(req, res);
  });
  server.addListener('upgrade', function(req,res){
      res.end();
  });
  
  sockjs_echo.installHandlers(server, {prefix:'/echo'});
  
  console.log(' [*] Listening on 0.0.0.0:442' );
  server.listen(442, '0.0.0.0');
  </code></pre>
  
  <p>Here is the original client code from the sockjs example (with changes noted in code), basically getting the inp.val() x 1000 as the beat for easy testing</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;&lt;head&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="http://cdn.sockjs.org/sockjs-0.3.min.js"&gt;&lt;/script&gt;
      &lt;style&gt;
        .box {
            width: 300px;
            float: left;
            margin: 0 20px 0 20px;
        }
        .box div, .box input {
            border: 1px solid;
            -moz-border-radius: 4px;
            border-radius: 4px;
            width: 100%;
            padding: 0px;
            margin: 5px;
        }
        .box div {
            border-color: grey;
            height: 300px;
            overflow: auto;
        }
        .box input {
            height: 30px;
        }
        h1 {
            margin-left: 30px;
        }
        body {
            background-color: #F0F0F0;
            font-family: "Arial";
        }
      &lt;/style&gt;
  &lt;/head&gt;&lt;body lang="en"&gt;
      &lt;h1&gt;SockJS Echo example&lt;/h1&gt;
  
      &lt;div id="first" class="box"&gt;
        &lt;div&gt;&lt;/div&gt;
        &lt;form&gt;&lt;input autocomplete="off" value=""&gt;&lt;/input&gt;&lt;/form&gt;
      &lt;/div&gt;
  
      &lt;script&gt;
          var sockjs_url = 'http://games.the-checkout-tech.com:442/echo';
          var sockjs = new SockJS(sockjs_url);
          $('#first input').focus();
  
          var div  = $('#first div');
          var inp  = $('#first input');
          var form = $('#first form');
  
          var print = function(m, p) {
              p = (p === undefined) ? '' : JSON.stringify(p);
              div.append($("&lt;code&gt;").text(m + ' ' + p));
              div.append($("&lt;br&gt;"));
              div.scrollTop(div.scrollTop()+10000);
          };
  
          sockjs.onopen    = function()  {print('[*] open', sockjs.protocol);};
          sockjs.onmessage = function(e) {print('[.] ', e.data); };
          sockjs.onclose   = function()  {print('[*] close');};
  
          form.submit(function() {
              print('[ ] sending', inp.val());
              // sockjs.send(inp.val());          // change
              startBeat();                        // change
              return false;
          });
  
          /******* Changes below ********/
          function startBeat() {
              window.setInterval(function() {
                  sockjs.send(getTime());
              }, inp.val() * 1000);   
          }
  
          function getTime() {
              var d = new Date();
              output = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
              return output;
          }
  
      &lt;/script&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>