Nodej.js low level websocket writing data to client

I am trying to understand how node low level websocket server works. Im ok sending data from client to server and unmasking the message is ok. But when I want to send (write) data to client from the server, the message is not received (in the browser nothing happens, but the message is sent from the server), and in the browser Im getting this error message when I send a object:

WebSocket connection to 'ws://localhost:8000/' failed: Unrecognized frame opcode: 11

This is the server code:

var http = require('http');
var server = http.createServer();

server.on('upgrade', function(req, socket, head){

    //Handshake accepted is ok:
    socket.write(handshake);
    console.log("-> Client accepted");


    //Reading data from client, and is ok:
    socket.on('data', function(data, start, end){...});


    //Send or write a message to client:
    var message_to_client = {
        data:"Message from the server"
    }

    if(socket.write(JSON.stringify()) ){
        console.log("Message sent");
    }else{
        console.log("Cant send the message");
    }

});

server.listen(8000, "127.0.0.1");

And this is the little part in the browser client:

var WebSocket = new WebSocket("ws://127.0.0.1:8000");

    WebSocket.addEventListener("open", function () {
        console.log("Connected to server");
    });

    //Write something to node server:
    WebSocket.send("Im a message from the client browser");


    /**
     * To read incoming data from the server, I have these listeners:
     */
    WebSocket.onmessage = function(event){
        console.log("This is show when the listener 1 is activated");
    }

    WebSocket.addEventListener("data", function (data) {
        console.log("This is show when the listener 2 is activated");
    });

    WebSocket.addEventListener("message", function (message) {
        console.log("This is show when the listener 3 is activated");
    });

And none of these listeners capture the data that server is sending. Thanks for helping, I cant find the answer to my problem in the websocket protocol RFC 6455.