title: WebSocket closes on send
body: <p>So I saw this great blog post, <a href="http://jeffkreeftmeijer.com/2010/experimenting-with-node-js/" rel="noreferrer" title="Experimenting with Node.js">Experimenting with Node.js</a>. I decided to try and set it up on my own using the author's <a href="https://gist.github.com/488562/90dfad4fc3bf52c136ecb5149c5bace53107c31d" rel="noreferrer">gist</a>. It didn't work.</p>
  
  <p>Further debugging shows me that the the websocket is connecting fine, but is closing as soon as 'send' is invoked. Here is the wireshark trace(forgive the weird spacing):</p>
  
  <pre><code>GET /test HTTP/1.1
  
  Host: 127.0.0.1:8000
  
  Sec-WebSocket-Key2: 3   j 92 9   62" 7 0 8 8
  
  Upgrade: WebSocket
  
  Connection: Upgrade
  
  Origin: http://127.0.0.1:3000
  
  Sec-WebSocket-Key1: 96'5% S72.93?06
  
  
  
  ......(bHTTP/1.1 101 WebSocket Protocol Handshake
  
  Upgrade: WebSocket
  
  Connection: Upgrade
  
  Sec-WebSocket-Origin: http://127.0.0.1:3000
  
  Sec-WebSocket-Location: ws://127.0.0.1:8000/test
  
  
  
  .4.R....mh.....{.{"action":"move","x":450,"y":22,"w":1146,"h":551}.
  </code></pre>
  
  <p>I've tried this in both Chrome and Firefox 4.0 beta. They both exhibit the same behavior. If I go to the <a href="http://jeffkreeftmeijer.com/2010/experimenting-with-node-js/" rel="noreferrer" title="Experimenting with Node.js">original blog site</a>, it works fine.</p>
  
  <p>Another thing. If I go into the JS console in either FF or Chrome and I do the following:</p>
  
  <pre><code>ws = new WebSocket('ws://localhost:8000/test')
  ws.send("foo")
  </code></pre>
  
  <p>It immediately disconnects and does not send the message. The server shows the connection and handshake, but never receives a message.</p>
  
  <p>I've found a few questions here that were similar but were either resolved without posting the fix or did not seem to apply in this situation. I can post the code from the <a href="https://gist.github.com/488562/90dfad4fc3bf52c136ecb5149c5bace53107c31d" rel="noreferrer">gist</a> if it will make it easier.</p>