title: Node.js + ws - websocket is unexpectedly closing
body: <p>I have a <strong>Node.js + ws</strong> server and a <strong>Qt client</strong>.  I'm having an issue with the websocket connection closing unexpectedly in certain conditions.  In my client, I iterate through a list of objects and send a series of requests to the server.  The server then accesses a database and then writes the response back to the client.  Here is the (simplified) basic server loop:</p>
  
  <pre><code>// ...
  
  var httpServer = http.createServer(//params);
  var WebSocketServer = require('ws').Server;
  var wss = new WebSocketServer({ server: httpServer });
  
  // ...
  
  wss.on('connection', function connection(ws) {
  
    ws.on('message', function incoming(msg) {
      handleRequest(JSON.parse(msg), function (err, result) {
        if (err) throw err;
        ws.send(JSON.stringify(result), function ack(error) {
          if (error) throw error;
        }
      }
    });
  
  });
  </code></pre>
  
  <p>If I limit the number of request from the client, everything works fine.  But if I reach a critical number of requests, data stops coming back from the server and the websocket connection times out.</p>
  
  <p>I'm wondering if I need to flush the websocket on the server before or after each write?  <strong>QtWebSocket</strong> has a <strong>flush()</strong> method, but I don't see this capability in the <strong>ws</strong> docs.  Any ideas would be appreciated.</p>
  
  <p>UPDATE: I should also note that no errors are sent to either <strong>ws</strong> or <strong>wss</strong>.  Data just stops flowing.</p>
  
  <p>UPDATE 2: Okay, this seems pretty clearly to be a problem with transmitting oversized packets from my client over the Internet to the node+ws server.  Based on Wireshark traces, once the oversize threshold is reached, the socket craps out, but only when I'm connected remotely to the server.  If the server is on my local subnet, oversized packets are properly transmitted to the server.  Any ideas how to debug this?</p>