title: Error sending JSON over webscket
body: <p>i have this small chat app in javascript and node and i am trying to send a simple JSON object over websocket, but it is displaying an error related to the "JSON.parse" i am doing in the server side. I've tried to change the code, but nothing seems to work. Why could this be?
  my operating system is windows 8.1 and i am using firefox and chrome.</p>
  
  <pre><code>undefined:1
  undefined
  ^
  SyntaxError: Unexpected token u
      at Object.parse (native)
      at WebSocketConnection.&lt;anonymous&gt; (C:\Users\*****\Documents\simple
  _chat\server.js:39:22)
  </code></pre>
  
  <p>here is the code on the client side</p>
  
  <pre><code>var socket = new WebSocket('ws://127.0.0.1:1234');
  
      function sendMessage(){
          var message = document.getElementById('message').value;
          var message_send ={
              name_:"WHATEVER",
              message_:message
          }
          socket.send(JSON.stringify(message_send));
      }
  
      socket.addEventListener("message", function(e){
          var msg = e.data;
          console.log(e);
          document.getElementById('chatlog').innerHTML+='&lt;br&gt;'+msg;
      })
  </code></pre>
  
  <p>here is the server code:</p>
  
  <pre><code>var count = 0;
  var client ={};
  
  var websocket = require('websocket').server;
  wsServer = new websocket({httpServer:server});
  
  wsServer.on('request',function(r){
      var connection = r.accept(null, r.origin);
      var id = count++;
      client[id]=connection
      console.log((new Date()) + ' Connection accepted [' + id + ']');
  
      connection.on('message', function (message) {
          var k = JSON.parse(message.data);
          var message_ = k.content_
          var name_ = k.name_;
          console.log(name_ +"  "+message_);
          for(var i in client){
              client[i].sendUTF(name_+":  "+message_);
          }
      });
  
      connection.on('close', function (reasonCode, description) {
          delete client[id];
          console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
      })
  })
  </code></pre>